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 blankOr to test for blank:
if($line !~ /\S/) { # line is blankThere'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.
In reply to Re: Re: Re: Newbie Question - arrays
by grantm
in thread Newbie Question - arrays
by mohadib_the_nasty
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |