The blank lines between records aren't blank - they contain spaces. If the data comes this way, I wouldn't be able to use the parsing method below. I had to delete all the spaces in the blank lines so they really were blank lines and then used the paragraph mode to read in 1 record at a time.

Anyhow, this is how I might parse the data (into the %data hash). Assumes RECORD_ID is unique for every set of owners and waiters.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %data; <DATA> for 1 .. 10; # toss out header { local $/ = ""; # paragraph mode while (<DATA>) { last if /^:/; my $owner; if (m{^(/.+)$}mg) { $owner = $1; } my @owner_rec = unpack "A13A13A2A10A8A5A8A9A*", $owner; $data{ $owner_rec[1] }{ owner } = \@owner_rec; my @waiter; while (m{^(/.+)$}mg) { my $waiter = $1; push @waiter, [ unpack "A13A13A2A10A8A5A8A9A*", $waiter ]; } $data{ $owner_rec[1] }{ waiter } = \@waiter; } } print Dumper \%data; __DATA__ UniData Release 7.2 Build: (3786) (c) Copyright Rocket Software, Inc. 1988-2009. All rights reserved. Current UniData home is /usr/udthome/. Current working directory is /usr/local/rfs/udt. :TERM ,0 :UDT.OPTIONS 20 ON :LOGTO /ud/JWP :LIST.QUEUE FILENAME RECORD_ID M OWNER UNBR UNO TTY TIME DA +TE /prod-data/J 00151120273 X jmorg 3584038 247 ts/49 13:38:12 Ju +l 20 ---------------------------------------------------------------------- +---- FILENAME RECORD_ID M WAITING UNBR UNO TTY TIME DA +TE /prod-data/J 00151120273 X jmorg 2015244 134 s/109 13:48:32 Ju +l 20 /prod-data/J 00151120273 X gdavi 1359996 62 ts/20 13:54:22 Ju +l 20 FILENAME RECORD_ID M OWNER UNBR UNO TTY TIME DA +TE /prod-data/J 001!L!311895 X jmorg 2015244 134 s/109 13:48:32 Ju +l 20 ---------------------------------------------------------------------- +---- FILENAME RECORD_ID M WAITING UNBR UNO TTY TIME DA +TE /prod-data/J 001!L!311895 X jmorg 5713932 191 ts/46 14:01:42 Ju +l 20 FILENAME RECORD_ID M OWNER UNBR UNO TTY TIME DA +TE /prod-datahi 001!10274882 X rfuse 3354796 61 ts/43 13:39:02 Ju +l 20 ---------------------------------------------------------------------- +---- FILENAME RECORD_ID M WAITING UNBR UNO TTY TIME DA +TE /prod-datahi 001!10274882 X jmorg 3584038 247 ts/49 13:39:22 Ju +l 20 :

This program print out the following (using Data::Dumper)

C:\Old_Data\perlp>perl t5.pl $VAR1 = { '001!L!311895' => { 'owner' => [ '/prod-data/J', '001!L!311895', 'X', 'jmorg', '2015244', '134', 's/109', '13:48:32', 'Jul 20' ], 'waiter' => [ [ '/prod-data/J', '001!L!311895', 'X', 'jmorg', '5713932', '191', 'ts/46', '14:01:42', 'Jul 20' ] ] }, '001!10274882' => { 'owner' => [ '/prod-datahi', '001!10274882', 'X', 'rfuse', '3354796', '61', 'ts/43', '13:39:02', 'Jul 20' ], 'waiter' => [ [ '/prod-datahi', '001!10274882', 'X', 'jmorg', '3584038', '247', 'ts/49', '13:39:22', 'Jul 20' ] ] }, '00151120273' => { 'owner' => [ '/prod-data/J', '00151120273', 'X', 'jmorg', '3584038', '247', 'ts/49', '13:38:12', 'Jul 20' ], 'waiter' => [ [ '/prod-data/J', '00151120273', 'X', 'jmorg', '2015244', '134', 's/109', '13:48:32', 'Jul 20' ], [ '/prod-data/J', '00151120273', 'X', 'gdavi', '1359996', '62', 'ts/20', '13:54:22', 'Jul 20' ] ] } }; C:\Old_Data\perlp>

In reply to Re: How to reference to array keys? by Cristoforo
in thread How to reference to array keys? by mmartin

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.