Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Split with consecutive delimeters

by jethro (Monsignor)
on Nov 01, 2013 at 00:27 UTC ( #1060666=note: print w/replies, xml ) Need Help??

in reply to Split with consecutive delimeters

Your words are contradicted by your example. "ab''c" has three elements delimited by 2 delimiters. $VAR2 in the output is not a placeholder for a delimiter, it represents what is between the two delimiters.

If you want to have delimiters also represented in the output, you can use this:

my @arr1 = split("(')", "ab''c");

UDPATE: It seems you want '' to be handled as one delimiter, but translated into empty strings.

my @arr1x = split("('+)", "ab''c"); my @arr1; foreach (@arr1x) { if (/'/) { push @arr1, ('') x length($_); } else { push @arr1, $_; } }

UPDATE2: Arrgh, we are communicating out of sync ;-)

Replies are listed 'Best First'.
Re^2: Split with consecutive delimeters
by nkuduva (Novice) on Nov 01, 2013 at 00:35 UTC
    Gotcha! Thanks for your reply. Your suggestion of split with delimiters in output is what I was looking for.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2022-05-29 09:55 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (101 votes). Check out past polls.