Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

How do I extract this data structure?

by HamNRye (Monk)
on Dec 09, 2000 at 21:37 UTC ( [id://45888]=perlquestion: print w/replies, xml ) Need Help??

HamNRye has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I work for a newspaper and we are trying to generate a page report from our classified system. We plan to do this by parsing the "PIL" file that calls all of the elements for pagination.

I need to get all of the "object" sections out of a file, and they are multi-line sections.

The file starts with a line like so:

pageoutput-5.0.1.0:20001201,TD,*,*,,FOO,2; {

Then there is a section that defines the path to the EPS's that make up the section:

name-table { "DAILY.evo" atex-itf unix-filename "/atexdata/clspag-d +ataD5/tmp/cpgfol2_018356_00" "1400.cm1" atex-itf unix-filename "/atexdata/clspag-da +taD5/furn-content/header/bin/T_1400.cm1" "1476 .wr1" atex-itf unix-filename "/atexdata/clspag-d +ataD5/furn-content/header/bin/T_1476.wr1" "608373" eps unix-filename "/atexdata/clspag-dataD5/ad +-content/71/1432671" .........(etc.)

Next section sets up the page dims:

canvas { user-name "ATEX-CLSPAG:20001201,TD,*,*,,F,2,WHEELS,2;" + units 35278 dimensions { 9360 15241 } application { app-name "ATEX-REFLEX" string { last-modified-time " +20001203:14:24:46" } string { status "UNDEFINED" } } }
And the we have "object" sections for each element:
object { origin { 0 0 } dimensions { 9360 130 } id "DAILY.evo" user-name "DAILY.evo" rc-name "DAILY.evo" application { app-name "ATEX-FPO-DUMMY-CONTROL" string { major-type "FRN" } string { ad-number "DAILY.evo +" } } } object { origin { 0 130 } dimensions { 900 1 } id "1400.cm1" user-name "1400.cm1" rc-name "1400.cm1" application { app-name "ATEX-FPO-DUMMY-CONTROL" string { major-type "FRN" } string { ad-number "1400.cm1" + } } }
And these repeat for each ad on the page. How would I get each of these object sections?? I would like to store them in a hash called %object and key them by the "id" field in the object section. I also will need to store the object origin and dimension.
example: %object{1400.cm1;originw} ; # References Origin Width for 1400.cm1
I know this must seem simple to many of you, but I don't really understand stepping through a file and getting this all out. Thanks for any help. (Didn't see this in TFM, but i might just not know where to look...) ~HamNRye

Replies are listed 'Best First'.
Re: How do I extract this data structure?
by davorg (Chancellor) on Dec 09, 2000 at 21:59 UTC

    Sounds to me like a perfect job for Parse::RecDescent. Get it from the CPAN.

Re: How do I extract this data structure?
by I0 (Priest) on Dec 24, 2000 at 21:30 UTC
    $b0 = qr/[^{}]/; $b1 = qr/\{($b0*)\}/; $xy = qr/\{\s*(\d+)\D+(\d+)\s*\}/; $string=qr/\bstring\s*$b1/; $application=qr/\bapplication\s*\{($string|$b0)*\}*/; $id=qr/\s*\bid\s*"(.*?)"/; $origin=qr/\borigin\s*$xy/; $dimensions=qr/\bdimensions\s*$xy/; $parts=qr/$application|$id|$origin|$dimensions|$string|$b0/; $object=qr/\bobject\s*{$parts*}/; $sections = join'',<DATA>; while( $sections =~ m/($object)/g ){ local $_=$1; @object{m/$id/} = { origin=>[m/$origin/], dimensions=>[m/$dimensions/], } } print keys %object; __DATA__ object { origin { 0 0 } dimensions { 9360 130 } id "DAILY.evo" user-name "DAILY.evo" rc-name "DAILY.evo" application { app-name "ATEX-FPO-DUMMY-CONTROL" string { major-type "FRN" } string { ad-number "DAILY.evo" } } } object { origin { 0 130 } dimensions { 900 1 } id "1400.cm1" user-name "1400.cm1" rc-name "1400.cm1" application { app-name "ATEX-FPO-DUMMY-CONTROL" string { major-type "FRN" } string { ad-number "1400.cm1" } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://45888]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-03-28 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found