Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Split Operation

by nagalenoj (Friar)
on Jul 30, 2009 at 12:52 UTC ( #784593=note: print w/ replies, xml ) Need Help??


in reply to Split Operation

use strict; use warnings; use Data::Dumper; my $test="[a,b],c,'d',[e,[f,g,h,[i,j],k,l],m,n],o,p"; my @array = split /,/,$test; my ($open, $current, @res); foreach (@array) { $current .= $_ if ($current or /\[/); $current .= ', ' if !(/\]/); $open++ if (/\[/); if (/\]/) { $open--; $current .= ', ' if ($open) ; } unless ($open) { if ( $current eq ', ') { push @res, $_; } else { push @res, $current; } undef $current; } } print Dumper \@res;
This code gives you what you want. Hope you are new to post threads in perlmonks and from next time please provide your code and the problem you are facing. It will tell us the way you have proceeded and it gives more understanding on the question.
I am not sure, whether this can be solved easily by using regex in split.


Comment on Re: Split Operation
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-07-29 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls