Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Split at multiple delimiters and get the delimiter

by jeffa (Bishop)
on Mar 01, 2011 at 21:27 UTC ( #890826=note: print w/ replies, xml ) Need Help??


in reply to Split at multiple delimiters and get the delimiter

Just add parens:

split /(:|%|;)/
and the delimiters will be captured ... but why put them in another array? Surely you won't be able to line them back up again ...

Update: regardless of why, you could do something like so:

/\W/ ? push @a,$_ : push @b,$_ for split /(:|%|;)/
Where @a would contain the delimiters and @b contains the data ...

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)


Comment on Re: Split at multiple delimiters and get the delimiter
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (17)
As of 2015-07-28 15:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (257 votes), past polls