Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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 drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2015-07-05 14:11 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 (67 votes), past polls