Your question isn't very clear but let's see what do you think about this:

open my $fd, '<', 'foo' or die open "$!\n"; my ($h, @arr); ## assuming <eor> and <eoh> are always at the end of their lines while (<$fd>) { $h .= $_; ## We store header in $h. I won't parse it. last if /<eoh>$/; } my $c = 0; while (<$fd>) { next if /^\n$/; my @fields = split / /, $_; foreach (@fields) { my ($k, $v) = $_ =~ /^(<[^>]+>)(.*)$/; next if $k eq '<eor>'; $arr[$c]{$k} = $v; } $c++ if /<eor>$/; } close $fd;

Output of use Data::Dumper;print Dumper \@arr;

$VAR1 = [ { '<time_on:6>' => '213400', '<app_jlog_eqsl_qsl_rcvd:1>' => 'Y', '<cont:2>' => 'NA', '<app_jlog_qso_number:4>' => '0001', '<app_jlog_eqsl_qsl_sent:1>' => 'Y', '<rst_rcvd:2>' => '59', '<qsl_sent_via:1>' => 'E', '<freq:2>' => '14', '<band:3>' => '20M', '<rst_sent:2>' => '59', '<cqz:1>' => '4', '<dxcc:1>' => '1', '<stx:1>' => '4', '<operator:3>' => 'VHF', '<pfx:3>' => 'VC3', '<ituz:1>' => '4', '<call:4>' => 'VC3O', '<qso_date:8:d>' => '20051029', '<app_jlog_lotw_qsl_sent:1>' => 'Y', '<srx:1>' => '4', '<mode:3>' => 'SSB', '<qsoComplete:1>' => '' }, { '<time_on:6>' => '183206', '<state:2>' => 'AB', '<cont:2>' => 'NA', '<contest_id:3>' => 'RAC', '<app_jlog_qso_number:4>' => '1257', '<app_jlog_eqsl_qsl_sent:1>' => 'Y', '<freq:8>' => '14.16299', '<rst_rcvd:2>' => '59', '<app_jlog_lotw_qslsdate:10>' => '2006-07-01', '<band:3>' => '20M', '<rst_sent:2>' => '59', '<cqz:1>' => '4', '<dxcc:1>' => '1', '<operator:3>' => 'MWB', '<stx:2>' => '27', '<pfx:3>' => 'VE6', '<operator:4>' => 'N7DQ', '<ituz:1>' => '2', '<srx:2>' => 'AB', '<qso_date:8:d>' => '20060701', '<app_jlog_lotw_qsl_sent:1>' => 'Y', '<app_jlog_eqsl_qslsdate:10>' => '2006-07-01', '<qsoComplete:1>' => '', '<mode:3>' => 'SSB', '<call:5>' => 'VE6GG' } ];

Update: Removed an intermediate step and did some other minor tweaks. Now it's smaller and probably faster.

--
David Serrano


In reply to Re: Parsing record into hash by Hue-Bond
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.