in reply to help needed with map
I managed to convert the section in your example into a string in JSON notation using the following:
my $section = [ [ "image1.gif" , "mark('a' ,1)" ], [ "image2.gif" , "mark('a' ,2)" ], ]; my $parsed = '[ ' . join( ' , ', map { '[ "' . join('" , "', @$_) . '" ]' } @ +$section ) . ' ]';
$parsed will contain the following string:
[ [ "image1.gif" , "mark('a' ,1)" ] , [ "image2.gif" , "mark('a' ,2)" +] ]
which is (I think) what you want. (There's an extra square bracket in your example, which I omitted.)
It does use map, among other things, though I'm not sure it qualifies for "clean-lookin". I found a CPAN module called JSON which produced the same result more cleanly, and would probably be easier to maintain:
use JSON; my $json = JSON->new; my $section = [ [ "image1.gif" , "mark('a' ,1)" ], [ "image2.gif" , "mark('a' ,2)" ], ]; my $parsed = $json->objToJson( $section );
|
|---|