in reply to opening a file destroys nulling entries in a list?!?!
$_ 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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: opening a file destroys nulling entries in a list?!?!
by sgifford (Prior) on Aug 07, 2003 at 03:32 UTC | |
|
Re: Re: opening a file destroys nulling entries in a list?!?!
by bobn (Chaplain) on Aug 07, 2003 at 03:38 UTC | |
by bobn (Chaplain) on Aug 07, 2003 at 03:45 UTC |