Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Parsing Text into Arrays..

by I0 (Priest)
on Jan 20, 2003 at 14:48 UTC ( #228351=note: print w/replies, xml ) Need Help??

in reply to Parsing Text into Arrays..

use strict; use Data::Dumper; sub lpcarray_to_array{ my ($larray)=@_; my @result=(); my $re = $larray; $re =~ s/((\([[{])|([]}]\))|.)/${[')','']}[!$3]\Q$1\E${['(','']}[! +$2]/gs; $re = join'|',map quotemeta,eval{$larray=~/$re/}; die $@ if $@; while( $larray=~/(\(\{($re)\}\))|(\(\[($re)\]\))|("([^"]*)")|(\d+) +/g ){ if( $1 ){ push @result,[lpcarray_to_array($2)]; }elsif( $3 ){ push @result,{lpcarray_to_array($4)}; }elsif( $5 ){ push @result,$6; }else{ push @result,$7; } } return @result; } print Dumper lpcarray_to_array qq(({ 1, 2, "three", 0, ({ "internal", +"array", 0, }) "end", })); print Dumper lpcarray_to_array qq(([ "key1": "value", "key2": ({ "valu +e", "array", }) ]));

Replies are listed 'Best First'.
Re: Re: Parsing Text into Arrays..
by Gilimanjaro (Hermit) on Jan 20, 2003 at 15:23 UTC
    Is this using the extensions in 5.6 that allow recursion in regex's?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2016-10-22 20:29 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (297 votes). Check out past polls.