Perl how to read a line from a file handle that is an array element -
my perl script takes number of files, opens them, , reads 1 line each. it's not working. here's code.
#!/bin/perl $numfile = scalar @argv; ($i = 0; $i < $numfile; ++$i) { open $fh[$i],"<",$argv[$i]; $line[$i] = <$fh[$i]>; } ($i = 0; $i < $numfile; ++$i) { print "$i => $line[$i]"; }
any ideas why doesn't work? illegal store file handles in array?
i expect print first line of each file. instead get
0 => glob(0x36d190)1 =>
i using perl v5.18.2
your <>
being interpreted file glob
instead of readline
.
use following explicitly specify intent:
$line[$i] = readline $fh[$i];
Comments
Post a Comment