Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 musing on the Monastery: (7)
As of 2014-10-25 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (142 votes), past polls