Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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?

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 scrutinizing the Monastery: (8)
As of 2015-11-29 15:32 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (751 votes), past polls