in reply to Re: Re: Newbie Question - arrays
in thread Newbie Question - arrays

Blank lines evaluate to true because in your case the blank line string is actually a string containing one character: the newline character.

When Perl reads in line-at-a-time mode (actually record-at-a-time mode) it reads up to and including the newline character (the default record separator). You can use chomp to remove the record separator:

@array = map { chomp; $_ } <MAIL>;

A handy way to check that a line is not blank is to check if it contains a non-whitespace character (newline is a whitespace character):

if($line =~ /\S/) { # line is not blank

Or to test for blank:

if($line !~ /\S/) { # line is blank

There's no need to anchor the regex with ^ and/or $ since we want it to match (and stop searching) on the first non-whitespace character it finds.