Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2016-10-25 15:32 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (323 votes). Check out past polls.