Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Parsing record into hash

by TedPride (Priest)
on Jul 04, 2006 at 21:52 UTC ( [id://559222]=note: print w/replies, xml ) Need Help??


in reply to Parsing record into hash

You didn't say what the record key for each record is, so I'm just adding the records to an overall array. I'm also not sure what the numbers inside the tags are for, so the following assumes that each tag is a key with no modifications.
use strict; use warnings; use Data::Dumper; my ($temp, @results) = ''; ### Fast forward past header while (<DATA>) { last if m/<eoh>\s+$/; } ### While there are records remaining... while (<DATA>) { $temp .= $_; ### Process if end of record tag reached if (m/<eor>\s+$/) { my %hash; $temp =~ s/\n//g; $temp =~ s/<eoh>.*//; $hash{$1} = $2 while $temp =~ /<(.*?)>([^<]*)\s/sg; push @results, \%hash; $temp = ''; } } print Dumper(\@results); __DATA__ Exported by jLog (c)2006 LA3HM, V 3.90.2.7 according to ADIF <adif_ver +:1>2 <PROGRAMID:4>jLog For jLog info: mailto:mail@jlog.org http://jlo +g.org/ Proposed ADIF2 Extensions may be included <eoh> <qso_date:8:d>20051029 <time_on:6>213400 <call:4>VC3O <band:3>20M <mod +e:3>SSB <operator:3>VHF <rst_sent:2>59 <rst_rcvd:2>59 <dxcc:1>1 <stx:1>4 <srx:1>4 <ituz:1>4 <cqz:1>4 <pfx:3>VC3 <cont:2>NA < +freq:2>14 <qsoComplete:1> <app_jlog_qso_number:4>0001 <app_jlog_eqsl_ +qsl_sent:1>Y <app_jlog_eqsl_qsl_rcvd:1>Y <app_jlog_lotw_qsl_sent:1>Y +<qsl_sent_via:1>E <eor> <qso_date:8:d>20060701 <time_on:6>183206 <call:5>VE6GG <band:3>20M <mo +de:3>SSB <operator:3>MWB <rst_sent:2>59 <rst_rcvd:2>59 <dxcc:1>1 <stx:2>27 <srx:2>AB <ituz:1>2 <cqz:1>4 <contest_id:3>RAC <pf +x:3>VE6 <cont:2>NA <freq:8>14.16299 <state:2>AB <qsoComplete:1> <app_ +jlog_qso_number:4>1257 <app_jlog_eqsl_qsl_sent:1>Y <app_jlog_eqsl_qsl +sdate:10>2006-07-01 <app_jlog_lotw_qsl_sent:1>Y <app_jlog_lotw_qslsda +te:10>2006-07-01 <operator:4>N7DQ <eor>

Replies are listed 'Best First'.
Re^2: Parsing record into hash
by sxmwb (Pilgrim) on Jul 04, 2006 at 22:07 UTC
    Ted,

    Thanks yet another way to do it. I love that about Perl. I appreciate the response and now have to read and understand what you have provided.

    Thanks Mike

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-25 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found