I tried to run the OP's code but there were some fatal errors. I re-wrote the code and I hope my explanation of it will help the OP.

The original code takes the approach of reading all of the data into a single variable, then splitting it out again to an array, then there are all sorts of subroutines to get rid of this, get rid of that...

I don't understand what the end objective really is, but from reading the OP's code, this whole thing has to do with record_id's. So I decided upon a hash structure keyed to record_id's.

There is a fundamental difference in the parsing approach. Rather than read the whole thing in and then go searching around for stuff to delete, I read each line and decide what to keep. Deciding what to keep is different than deciding what to throw away.

The file format illustrates something to avoid if you are designing a log file format. What a log line means is state dependent upon what a previous line said. There are of course reasons to have complex records in a log file, but very often a de-normalized flat "every line speaks for its self" is the best.

Anyway, the data is read line by line. If it is important, something happens. Everything that is not important is ignored. The only two types of lines that matter are: FILENAME lines and data lines. The lines starting with FILENAME tells us how to interpret the 4th field of subsequent data lines. So if a FILENAME line is seen, this bit of status is saved. A list slice is used to just get the 4th thing on the line.

It appears that all of the data lines start with a '/' so I picked that to check against. If a data line is seen, then I get the 2nd column (the record number) and use that in conjunction with the state variable that tells us whether this is the owner or waiting. Then that line gets saved in the data structure.

So that's it! Two if statement do the whole job! There is no "oh, this is a special case at the beginning so we throw away the first 10 lines, or this funny line with ':' in column 1 is what ends the data. If the data format was not dependent upon the previous FILENAME line, then there would be only one if statement.

I did not parse each line to the nth degree. Often that's not necessary and here it would just over complicate what is already a complex data structure, HoHoA. There is a simple sub to split a line out into a hash. I return the hash as a flattened list for simplicity.

I guess it will become apparent what kind of reports are needed with an update from the OP. I show one report. The __DATA__ segment and Data::Dump output is long so that is in a readme section.

#!/usr/bin/perl use strict; use warnings; use Data::Dump qw(pp); #Data::Dumper is also great! my %recordState; #recordid=>OWNER|WATING=>line my $OwnerOrWaiting=""; while (<DATA>) { s/\s+$//; # delete trailing whitespace if (/^FILENAME/) { $OwnerOrWaiting = (split)[3]; } if (m|^/|) { my ($record_id) = (split)[1]; push @{$recordState{$record_id}{$OwnerOrWaiting}}, $_; } } sub get_fields { my $line = shift; my %fields; @fields{qw(FILENAME RECORD_ID M USER UNBR UNO TTY TIME DATE)} = split(' ', $line, 9); return %fields; } print "The record numbers are:\n"; print "\t$_\n" foreach (keys %recordState); # I don't know what kind of queries you want, but # for example print some basic data for any queue's that # have 2 or more people waiting... foreach my $recNum ( keys %recordState) { if ( @{$recordState{$recNum}{WAITING}} >= 2) { print "Hey, there are at least 2 guys in this crowd!\n"; foreach my $line ( @{$recordState{$recNum}{WAITING}} ) { my %temp = get_fields($line); #this next is a hash slice... print "@temp{'RECORD_ID','USER','TIME','DATE'}\n"; } } } print "Dumping data...\n"; foreach my $recHashref ( values %recordState) { print "OWNER $_\n", for @{$recHashref->{OWNER}}; print "WAITING $_\n", for @{$recHashref->{WAITING}}; } print pp(\%recordState); =OUTPUTS The record numbers are: 001!L!311895 001!10274882 00151120273 Hey, there are at least 2 guys in this crowd! 00151120273 jmorg 13:48:32 Jul 20 00151120273 gdavi 13:54:22 Jul 20 Dumping data... OWNER /prod-data/J 001!L!311895 X jmorg 2015244 134 s/109 13: +48:32 Jul 20 WAITING /prod-data/J 001!L!311895 X jmorg 5713932 191 ts/46 14: +01:42 Jul 20 OWNER /prod-datahi 001!10274882 X rfuse 3354796 61 ts/43 13: +39:02 Jul 20 WAITING /prod-datahi 001!10274882 X jmorg 3584038 247 ts/49 13: +39:22 Jul 20 OWNER /prod-data/J 00151120273 X jmorg 3584038 247 ts/49 13: +38:12 Jul 20 WAITING /prod-data/J 00151120273 X jmorg 2015244 134 s/109 13: +48:32 Jul 20 WAITING /prod-data/J 00151120273 X gdavi 1359996 62 ts/20 13: +54:22 Jul 20 =cut
=And rest of the story, pp() output and __DATA__ { "001!10274882" => { OWNER => [ "/prod-datahi 001!10274882 X rfuse + 3354796 61 ts/43 13:39:02 Jul 20", ], WAITING => [ "/prod-datahi 001!10274882 X jmorg + 3584038 247 ts/49 13:39:22 Jul 20", ], }, "001!L!311895" => { OWNER => [ "/prod-data/J 001!L!311895 X jmorg + 2015244 134 s/109 13:48:32 Jul 20", ], WAITING => [ "/prod-data/J 001!L!311895 X jmorg + 5713932 191 ts/46 14:01:42 Jul 20", ], }, "00151120273" => { OWNER => [ "/prod-data/J 00151120273 X jmorg + 3584038 247 ts/49 13:38:12 Jul 20", ], WAITING => [ "/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", ], }, } =cut __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

In reply to Re: How to reference to array keys? by Marshall
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.