in reply to Split Operation
my $test="xyz,[a,b],c,'d',[e,[f,g,h,[i,j],k,l],m,n],o,p"; my @stack = []; for (split /([\[\],])/, $test) { next unless length $_; next if $_ eq ','; push @stack, [] and next if $_ eq '['; push @{ $stack[-2] }, pop @stack and next if $_ eq ']'; push @{ $stack[-1] }, $_; } my $retval = $stack[0];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Split Operation
by santhosh_89 (Scribe) on Aug 03, 2009 at 05:53 UTC |