Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
go ahead... be a heretic
 
PerlMonks  

Re: Split and empty strings

by TheoPetersen (Priest)
on Apr 10, 2001 at 15:22 UTC ( [id://71366]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 15: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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://71366]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.