in reply to efficient Array printing to a file
A more common idiom for printing to a file would be this:foreach $x (@x) { open ($x, ">>$log") or die; print while (<$x>); printf "%7d",$x; } close ($x);
Catching possible errors from your system IO operations in $! is generally a good practice. Also, the version I showed doesn't reopen the filehandle every time you want to print a array element to the file. The join operator is very useful, do a perldoc -f join if you've never seen it before. A perldoc -f open would probably be helpful to you as well.open (OUTPUT, ">>$log") or die "Error opening file $log ($!)\n"; my $line = join ' ', @x; print OUTPUT $line, "\n"; close (OUTPUT) or die "Error closing file $log ($!)\n";
Hope that this helps. :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: efficient Array printing to a file
by Anonymous Monk on May 27, 2004 at 23:01 UTC |