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


In reply to Re: Re: Script doesn't enter while loop. by ChemBoy
in thread Script doesn't enter while loop. by alienhuman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.