in reply to Re: Split pattern doesn't match last line of file
in thread Split pattern doesn't match last line of file

guess it's a bit to advanced for me as I can't get it working though I understand the solution. Could you elaborate a bit more on where to put the
next if $line =~ m/^\s+$/; and the $_?

Replies are listed 'Best First'.
Re^3: Split pattern doesn't match last line of file
by bobf (Monsignor) on Jan 02, 2007 at 05:47 UTC

    Sure - sorry for being too cryptic. Sometimes it's hard to tell how much detail is needed. :-)

    Insert a new line as follows (code snippet taken from your OP):

    while (<>) { next if m/^\s+$/; # <-- add this line my @cellen = ( split /,/, )[ 3, 4 ];

    The regex is anchored to the start (^) and end ($) of the string, and the pattern consists of one or more white space characters (\s+). See perlre and Pattern Matching, Regular Expressions, and Parsing (in the Tutorials section) for more information.

    Incidently, the code I added is a bit shorter than it could be, since it utilizes $_. A more verbose version could be:

    next if $_ =~ m/^\s+$/;
    or, if you wanted to explicitly assign the input text to a variable before processing, you could do something like this:
    while ( my $line = <>) { next if $line =~ m/^\s+$/; # <-- add this line my @cellen = ( split( /,/, $line ) )[ 3, 4 ];

    HTH