Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Surprised by split

by davorg (Chancellor)
on Aug 11, 2005 at 10:06 UTC ( [id://482889]=note: print w/replies, xml ) Need Help??


in reply to Surprised by split

The '\' has a special meaning in a double-quoted string. And _also_ a special meaning in a regex. You'll need two of them in order to break through both special meanings.

But the first argument to "split" should be a regex. So don't pass it a string :)

See... now I'm wondering about split qr(\|) and split m/\|/.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Surprised by split
by extremely (Priest) on Aug 11, 2005 at 14:18 UTC
    Hmm:
    $ perl -e '$a="m|b|a"; print join(",",split "\\|",$a),$/' m,b,a $ perl -e '$a="m|b|a"; print join(",",split /\|/,$a),$/' m,b,a $ perl -e '$a="m|b|a"; print join(",",split m/\|/,$a),$/' m,b,a $ perl -e '$a="m|b|a"; print join(",",split qr/\|/,$a),$/' m,b,a $ perl -e '$a="m|b|a"; $b=qr/\|/; print join(",",split $b,$a),$/' m,b,a $ perl -e '$a="m|b|a"; sub b{return qr/\|/}; print join(",",split b(), +$a),$/' m,b,a $ perl -e '$a="m|b|a"; print join(",",split "[|]",$a),$/' m,b,a

    Man, I love perl. :) (Updated a couple of times to add new variations)

    --
    $you = new YOU;
    honk() if $you->love(perl)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-18 04:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found