in reply to Parsing a multiline data structure

If you can describe a yacc-like grammer for this, you may be interested in Parse::RecDescent, which would pull all of this into Perl for you. I don't have much experience with it, but for complex or nested data, it's usually going to be easier to use than, say, Perl regular expressions at getting at this data.

Replies are listed 'Best First'.
Re: Re: Parsing a multiline data structure
by HamNRye (Monk) on Dec 10, 2000 at 02:31 UTC
    Goes to show that if you plug away the answer will come....
    while (<PIL>) { # print ; if (m/\ *object\ \{/) { @lines = $_ ; $objcount++ ; } elsif (m/^\ *\}/) { &Parse_Obj(@lines) ; # print "Found Match!\n" ; } else { push @lines, $_ ; } } sub Parse_Obj { $id = @_[3] ; $origin = @_[1] ; $dims = @_[2] ; $id =~ s/^.*?\"//g ; #remove up to first " $id =~ s/\".*\n$//g ; #remove everything from last " $origin =~ s/^.*?\{\ //g ; #remove up to first { $origin =~ s/\ \}.*\n$//g ; #remove from last } $dims =~ s/^.*?\{\ //g ; #remove up to first { $dims =~ s/\ \}.*\n$//g ; #remove from last } ( $originw, $originh ) = split / /, $origin ; ( $dimsw, $dimsh ) = split / /, $dims ; # print "$objcount : $id $originw $originh $dimsw $dimsh \n" ; if (exists($object{$objcount})) { break } else { $object{"$objcount$;id"} = $id ; $object{"$objcount$;originw"} = $originw ; $object{"$objcount$;originh"} = $originh ; $object{"$objcount$;dimsw"} = $dimsw ; $object{"$objcount$;dimsh"} = $dimsh ; } } # print "join(" ", %object) \n" ; for ($count < $objcount) { print "$object{$count,id} $object{$count,originw} $object{$count,origi +nh} \n" ; }
    Thanks for everybody's help. ~Das Ham Man