$_ is a global variable. Your while is setting it to the last record of your filehandle and since your files end with a \n, $_ returns blank (I guess $_ gets set before the test is done to see if it has a value). Since this is Perl there is more than one way to get around this:
You can localize $_ in your sub like so:
Or you can set each line of the file to a variable in the while like so:sub screwed { my ($in) = @_; local $_; # basically a temporary $_ just for this sub open(IN, "<$in"); while(<IN>) { print "file $in contains $_"; } close(IN); }
while(defined(my $foo = <IN>)) { print "file $in contains $foo"; }
Hope that helps
Lobster Aliens Are attacking the world!In reply to Re: opening a file destroys nulling entries in a list?!?!
by cfreak
in thread opening a file destroys nulling entries in a list?!?!
by matpalm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |