perl split on empty file

Posted by Casey on Stack Overflow See other posts from Stack Overflow or by Casey
Published on 2010-05-06T16:09:06Z Indexed on 2010/05/06 16:18 UTC
Read the original article Hit count: 367

Filed under:

I have basically the following perl I'm working with:

open I,$coupon_file or die "Error: File $coupon_file will not Open: $! \n";
while (<I>) {
 $lctr++;
 chomp;
 my @line = split/,/;
 if (!@line) {
     print E "Error: $coupon_file is empty!\n\n";
     $processFile = 0; last;
 }
}

I'm having trouble determining what the split/,/ function is returning if an empty file is given to it. The code block if (!@line) is never being executed. If I change that to be

if (@line)

than the code block is executed. I've read information on the perl split function over at http://perldoc.perl.org/functions/split.html and the discussion here about testing for an empty array but not sure what is going on here.

I am new to Perl so am probably missing something straightforward here.

Thanks.

© Stack Overflow or respective owner

Related posts about perl