[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Help splitting encoded lists of lists



|$lol = '{{22, "foo o", "oof"}, {7, "bar b", ""}, {99, "x y, z", "bix baz"}}';
|I want to split $lol into a nice 2D array [...]

This has nothing specifically to do with MacPerl, so it should have been
posted to comp.lang.perl.misc, not sent to this list.

However, being I've wasted everyone's time already, I might as well answer
the question. Read up on eval. eval is your friend:

$lol = '{{22, "foo o", "oof"}, {7, "bar b", ""}, {99, "x y, z", "bix baz"}}';

%conv = ('{' => '[', '}' => ']');
$conv = join '', keys %conv;

$lol =~ s/[$conv]/$conv{$&}/oeg;

$items = eval $lol;

print "\$items->[0][0] = $items->[0][0]\n";
print "\$items->[0][1] = $items->[0][1]\n";
print "\$items->[0][2] = $items->[0][2]\n";
print "\$items->[1][0] = $items->[1][0]\n";
print "\$items->[1][1] = $items->[1][1]\n";
print "\$items->[1][2] = $items->[1][2]\n";
print "\$items->[2][0] = $items->[2][0]\n";
print "\$items->[2][1] = $items->[2][1]\n";
print "\$items->[2][2] = $items->[2][2]\n";

Brian

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch