in reply to Re^7: Filtering Output from two files
in thread Filtering Output from two files
You have an error in this line:
while (my ($row) = <$fh2>) {
Since $row is in parenthesis, you're doing an assignment in list context. So all the lines in $fh2 are read, and the first one is passed into $row, and the rest are discarded.
Change the line to:
while (my $row = <$fh2>) {
and then it should work better for you.
Here's a little demonstration:
$ cat t.pl use strict; use warnings; # Scalar context my $row = <DATA>; print $row; # Array context my ($a) = <DATA>; print $a; # Now there's nothing left! my $c = <DATA>; print $c; __DATA__ Now is the time for all good men to come to the aid of their party $ perl t.pl Now is the time for all good men Use of uninitialized value $c in print at t.pl line 14, <DATA> line 5.
Notice that we read the first line in scalar context, and then we print the first line successfully.
Next, we read a line in array context, and print the second line successfully.
Finally, we try to read the next line, but there's no data left! All of it was read earlier!
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Filtering Output from two files
by Anonymous Monk on Feb 06, 2018 at 09:12 UTC | |
by Anonymous Monk on Feb 06, 2018 at 09:22 UTC | |
by roboticus (Chancellor) on Feb 06, 2018 at 18:11 UTC |