desertman has asked for the wisdom of the Perl Monks concerning the following question:

Dear Holy Brethren,

regarding a list data structure and a file I know use this for input:

open FILEIN, "<$fn" or die $!;

@out = <FILEIN>;

But is anything equivalent for output? ie:

open FILEOUT, ">$fn" or die $!;

<FILEOUT> = @out;

from my cave in deepest humility

Replies are listed 'Best First'.
Re: noobie write list to file out
by GrandFather (Saint) on Nov 23, 2009 at 03:36 UTC

    Much better to use strictures (use strict; use warnings;), lexical file handles and three parameter open:

    use strict; use warnings; open my $inFile, '<', $fn or die "Failed to open $fn: $!"; open my $outFile, '>', $fo or die "Failed to open $fo: $!"; while (<$inFile>) { ... print $outFile "..."; } close $inFile; close $outFile;

    Oh, and don't slurp files (use while (<$inFile>) instead).

    Update: fixed typo in code - thanks wfsp


    True laziness is hard work

      Also the increasingly popular use autodie qw/open close/; - autodie.

      Just a something something...
Re: noobie write list to file out
by keszler (Priest) on Nov 23, 2009 at 01:20 UTC