in reply to Split and empty strings

Are the empty lines at the end, perhaps? By default, split trims the returned list at the first empty value. See perlfunc:split for the exact terms.

Update: I just tried this code, and it works as I expect.

$_ = "one two three four "; foreach my $line (split(/\n/)) { print "$line\n"; }
The output for my Perl 5.6.1 system is:

$ perl ~/split.pl
one
two
three

four
with the blank printed between three and four, and nothing thereafter.

Replies are listed 'Best First'.
Re: Re: Split and empty strings
by andye (Curate) on Apr 10, 2001 at 19:29 UTC
    No, they're scattered randomly through the string. But thanks for the idea, TheoPetersen. I've looked at perlfunc:split again - still no joy.

    Slight modification - I've realised I don't need the /m on the regexp. Works the same without.

    andy.

    update: thanks again. I've realised that I was being stupid - the onset of tunnel vision. split was doing exaclty what it ought, as your example shows, but the regexp was returning extra blank lines.