I've run the following using -w, with only one minor complaint. Also run it using -d, and found that for some reason, it doesn't enter the while loop on line 14. Can anyone help me figure out why I'm not entering the while? The script doesn't die on the filehandle open, so I know that's not a problem. There is one detail that might be important--the file I'm opening with has only a single line and doesn't have a "\n" at the end. I would like to have a script that can deal with single and multi-lined files though.
#!/usr/bin/perl if (!$ARGV[0]) { die "Please include the name of a comma-delimited text file as + argument. "; } elsif ( ($ARGV[0] eq "help") or ($ARGV[0] eq "-h") or ($ARGV[0] eq " +--help") ) { die "Please include the name of a comma-delimited text file as + argument. "; } else { $FILE = $ARGV[0]; open FILE or die "Couldn't open file $FILE: $!\n"; #open(FILE,"$FILE") or die "Couldn't open file $FILE: $!\n"; while (<FILE>) { $file_data=<FILE>; } close FILE; @new_array = split /,/, $file_data; $i=1; open LOG, '>>./array_parser.log'; print LOG localtime() . "\n"; foreach $item (@new_array) { print LOG "Item i => $item\n"; $i++; } print LOG "-------- END --------\n\n"; close LOG; };

In reply to 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.