www.perl.com
Perl Programming
Writing to Files
  • Writing to files
    • print writes to a file
    • print writes to a STDOUT by default
    • Be sure that the file is open for writing first

        open CUSTOMERS, "< mailing_list" or die "Can't open input file: $!";
        open LABELS,    "> labels"       or die "Can't open output file: $!";

        while (my $line = <CUSTOMERS>) {
          my @fields = split(":", $line);
          print LABELS "$fields[1] $fields[0]\n";
          print LABELS "$fields[3], $fields[4]\n";
          print LABELS "$fields[5], $fields[6]  $fields[7]\n";
        }
      
Previous http://stuff.mit.edu/iap/perl/