Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Need Record Parsing Advice

by unobe (Scribe)
on Mar 03, 2006 at 08:30 UTC ( #534167=note: print w/ replies, xml ) Need Help??


in reply to Need Record Parsing Advice

I'd use Tie::File and set the record separator. Then use some multiline regexes. I tested your data out on the following code, and it worked like a charm.

use strict; use warnings; use Tie::File; my ($record, @array, %data) = (0); my $file = 'whatever'; tie @array, 'Tie::File', $file, recsep => '=' x 30 . "\n"; while ($array[$record]) { $record++, next unless $array[$record] =~ m/^[^=]/; @{$data{$record}}{'primary', 'level', 'group', 'id_node', 'inverse', 'secondaries'} = $array[$record] =~ m/# get primary id, level, and group Primary[^:]+ \D+(\d+) \D+(\d+) \D+(\d+) # then the id-node and inverse (?:[^:]+:){4} \D+(\w+) \D+(\d+) # skip 'Secondary ID' line [^K]+ # and grab the rest until end of record ([^=]+) /gxms; $record++; } for my $rec (keys %data) { for (keys %{$data{$rec}} ) { print $_ . ' is set to ' . $data{$rec}{$_} . "\n"; } }


Comment on Re: Need Record Parsing Advice
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2015-07-07 13:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls