Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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", }) ]));


Comment on Re: Parsing Text into Arrays..
Download Code
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?
      no

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-12-23 00:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls