in reply to Re: Script doesn't enter while loop.
in thread Script doesn't enter while loop.

Or even

my $file_data = <FILE>;
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).

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:

foo,bar fooey
and got the following sequence in the debugger (note that the empty command statements are all interpreted as "n"):
main::(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 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 us
DB<1> x $file_data 0 'fooey ' DB<2> x $_ 0 'foo,bar '
which is what one would expect. And continuing on, we get
DB<3> main::(alienhuman.pl:21): close FILE; DB<3> main::(alienhuman.pl:23): @new_array = split /,/, $file_ +data;
which seems to blissfully ignore the fact that it already told you it had closed that filehandle.

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. :-)



If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders