use Data::Dump::Streamer; my $string; while (<DATA>) { chomp; s/\r//; # append a comma to lines not ending in 'Array' or '(' # or being (other than containing whitespace) empty lines $_ .= ',' unless /(Array|\(|^\s*)$/; $string .= $_."\n"; } sub Array { my %h; while(@_) { my ($key) = @{shift(@_)}; $h {$key} = shift(@_); } \%h; } print $string,"\n"; my $ref = eval $string; Dump $ref; __DATA__ Array ( [0] => Array ( [attrs] => Array ( [0] => Array ( [key] => rat1 [value] => -10 [options] => 0 [type] => 0 ) [1] => Array ( [key] => rat1 [value] => -10 [options] => 0 [type] => 0 ) ) [mesg_id] => 1 [parent_id] => 0 [thread_id] => 1 [cat_id] => 3 [folder_id] => 0 [status] => 4 ) )
Output:
Array ( [0] => Array ( [attrs] => Array ( [0] => Array ( [key] => rat1, [value] => -10, [options] => 0, [type] => 0, ), [1] => Array ( [key] => rat1, [value] => -10, [options] => 0, [type] => 0, ), ), [mesg_id] => 1, [parent_id] => 0, [thread_id] => 1, [cat_id] => 3, [folder_id] => 0, [status] => 4, ), ), $HASH1 = { 0 => { attrs => { 0 => { key => 'rat1', options => 0, type => 0, value => -10 }, 1 => { key => 'rat1', options => 0, type => 0, value => -10 } }, cat_id => 3, folder_id => 0, mesg_id => 1, parent_id => 0, status => 4, thread_id => 1 } };
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re: String to PERL data structure
by shmem
in thread String to PERL data structure
by perl_lover
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |