Or even
if you don't like useless parentheses. :-) (Note that those parentheses are far from useless under other circumstances-- you just don't need them here).my $file_data = <FILE>;
For the problem of "not entering the while loop", note that the debugger does some strange and curious things around loops sometimes. I tested your code with the following two-line input:
and got the following sequence in the debugger (note that the empty command statements are all interpreted as "n"):foo,bar fooey
which I think is closely related to what you said about "not entering the while loop". The good news is that checking the contents of the variables at this point gives usmain::(alienhuman.pl:3): if (!$ARGV[0]) { DB<1> n main::(alienhuman.pl:6): } elsif ( ($ARGV[0] eq "help") or ($AR +GV[0] eq "-h") or ($ARGV[0] eq "--help") ) main::(alienhuman.pl:7): { DB<1> main::(alienhuman.pl:12): $FILE = $ARGV[0]; DB<1> main::(alienhuman.pl:14): open FILE or die "Couldn't ope +n file $FILE: $!\n"; DB<1> main::(alienhuman.pl:21): close FILE; DB<1> main::(alienhuman.pl:18): $file_data=<FILE>; DB<1> main::(alienhuman.pl:17): while (<FILE>) {
which is what one would expect. And continuing on, we getDB<1> x $file_data 0 'fooey ' DB<2> x $_ 0 'foo,bar '
which seems to blissfully ignore the fact that it already told you it had closed that filehandle.DB<3> main::(alienhuman.pl:21): close FILE; DB<3> main::(alienhuman.pl:23): @new_array = split /,/, $file_ +data;
I would characterize this as a bug, but there may be logic behind it that I'm not aware of. In any case, it's something to know in case you ever have to debug a program with a while loop in it again. :-)
In reply to Re: Re: Script doesn't enter while loop.
by ChemBoy
in thread Script doesn't enter while loop.
by alienhuman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |