Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Why does split on /./ not split the string?

by GrandFather (Saint)
on Dec 07, 2005 at 09:46 UTC ( [id://514764]=note: print w/replies, xml ) Need Help??

in reply to Why does split on /./ not split the string?

It does. However because the . matches anything, the result may not be what you expect: all the chars are delimiter chars so no fields are found.

DWIM is Perl's answer to Gödel
  • Comment on Re: Why does split on /./ not split the string?

Replies are listed 'Best First'.
Re^2: Why does split on /./ not split the string?
by ChemBoy (Priest) on Dec 07, 2005 at 18:55 UTC

    Just to expand on this theme a bit, you can get those empty fields returned if you really want them, by passing -1 as the third argument to split: split /./,'abcde',-1 will dutifully return six empty strings. (Cases with values other than -1 are left as an exercise to the extremely bored.) Of course, there are probably faster ways to count the characters in your string, but that's a side issue. :-)

    If God had meant us to fly, he would *never* have given us the railroads.
        --Michael Flanders

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://514764]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2024-04-15 16:11 GMT
Find Nodes?
    Voting Booth?

    No recent polls found