What's the easiest way to write to a file using Perl?

perl

Solution

EDIT (By popular and editable demand)

http://perldoc.perl.org/functions/open.html

In your case you would have to :

  #21st century perl.
  my $handle;
  open ($handle,'>>','/home/shared/ftp') or die("Cant open /home/shared/ftp");
  print $handle "$panel_login $panel_password $root_name $root_pass $port $panel_type";
  close ($handle) or die ("Unable to close /home/shared/ftp");

Alternatively, you could use the autodie pragma (as @Chas Owens suggested in comments). This way, no check (the or die(...)) part needs to be used.

Hope to get it right this time. If so, will erase this Warning.

Old deprecated way

Use print (not one liner though). Just open your file before and get a handle.

open (MYFILE,'>>/home/shared/ftp');
print MYFILE "$panel_login $panel_password $root_name $root_pass $port $panel_type";
close (MYFILE);

http://perl.about.com/od/perltutorials/a/readwritefiles_2.htm

Problem

Currently I am using ``` system("echo $panel_login $panel_password $root_name $root_pass $port $panel_type >> /home/shared/ftp"); ``` What is the easiest way to do the same thing using Perl? IE: a one-liner.

Original source