Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Split Operation

by santhosh_89 (Scribe)
on Aug 03, 2009 at 05:53 UTC ( #785346=note: print w/ replies, xml ) Need Help??


in reply to Re: Split Operation
in thread Split Operation

Dear Happy.Barney I tested your perl source code,You have splited the scalar value based on the open and close bracket.So it is failing one of the test case.I gave following input/output.

#!/usr/bin/perl use strict; use warnings; my $test="[a[a]]"; 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]; use Data::Dumper; print Dumper($retval); $VAR1 = [ [ 'a', [ 'a' ] ] ]; The output should be as following. $VAR1 = [ [ 'a[a]' ] ];


Comment on Re^2: Split Operation
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2015-07-29 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (261 votes), past polls