in reply to Parsing a multiline data structure

I've found the other solutions quite illuminating, but not wanting to be left out (and because I already did it ;-), here's my kick at it. The patterns could use some loosening on whitespace, I'm hoping no objects have missing attributes (you'd get the previous ones), and you can't have an object nested inside another with this, but it appears sufficient for the sample data. Hmm... I'm also ignoring the extraction of entire objects that tilly handles so well. Now I'll go read up on Parse::RecDecent - so many monks can't be wrong!

use strict; my %object; open IN, '<'.pop or die "can't open data: $!\n"; until(<IN> =~ /^object\s*\{/) {}; #skip ahead to the body of the fir +st object{} my($id, $origin, $dims); while(<IN>) { SWITCH: { /id "(.+)"/ && do { $id = $1; last SWITCH; }; /origin \{ (\d+) (\d+) \}/ && do { $origin = "$1,$2"; last SWITCH; }; /dimensions \{ (\d+) (\d+) \}/ && do { $dims = "$1,$2"; last SWITCH; }; (/^object\s*\{/ || eof(IN)) && do { $object{$id}{'origin'} = + $origin; $object{$id}{'dims'} = + $dims; }; # default: on to the next line }#SWITCH } foreach my $id (keys %object) { print "$id: "; foreach my $attr (keys %{$object{$id}} ) { print "$attr = $object{$id}{$attr} "; } print "\n"; }
produces:
DAILY.evo: origin = 0,0 dims = 9360,130 1400.cm1: origin = 0,130 dims = 900,1

--
I'd like to be able to assign to an luser