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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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>

In reply to Re: Parsing record into hash by TedPride
in thread Parsing record into hash by sxmwb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2024-04-18 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found