Hello,
First, I would follow ww's suggestion and add use strict; use warnings; *(and even use diagnostics; use Data::Dumper for a more verbose explanation of any errors and debugging the return value of your variables.)

I would also suggest taking a look at the Perl Data Structures Cookbook: perldsc.

As far as the example of data you provided:

2011-04-03 09:37:12.129 (INFO, ICELineHandler.cpp:339) Product Def Mar +ketID 90120253, Symbol 'BRN FMU0012_OMCA0000118502081312' 2011-04-09 21:32:15.525 3509,3523: Gap detect on 233.156.208.41:20041 +from 2746318 to 2746373, moving to next message 2011-04-09 21:32:15.585 3509,3523: Gap detect on 233.156.208.41:20041 +from 2746420 to 2746475, moving to next message 2011-04-09 21:32:15.639 3509,3522: Received data on ConnectionICE-Opti +ons. Pending=214044. 2011-04-03 09:37:12.129 (INFO, ICELineHandler.cpp:339) Product Def Mar +ketID 90120253, Symbol 'BRN FMU0012_OMCA0000118502081312'

It doesn't seem as if you're showing us an example line that would meet the requirements you describe (If I'm understanding them correctly). Are you looking to ultimately have something like this:

#!/usr/bin/perl use strict; use warnings; use diagnostics; use Data::Dumper; my $Messages = { '21:32:15.111' => ["233.156.208.11:2004", "214111"], # Us +ing the Time Stamp as a key '21:32:15.222' => ["233.156.208.22:2004", "214222"], # to + an anonymous array containing '21:32:15.333' => ["233.156.208.33:2004", "214333"], # mi +lliseconds and "Pending Number". }; print Dumper($Messages); # Us +ed to check the contents of your variables. __END__ $VAR1 = { '21:32:15.222' => [ '233.156.208.22:2004', '214222' ], '21:32:15.111' => [ '233.156.208.11:2004', '214111' ], '21:32:15.333' => [ '233.156.208.33:2004', '214333' ] };

A few other things I noticed that you may want to review:

while ( $line = <LOG> ) { unless (($data[10] =~ m/Pending=/) || ($data[6] =~ m/Gap/)) { next; } +# skip elements we don't want if ($line =~ m/Pending=/) { my @data=split(/ /,$line); # split the line up $data[10] =~ s/[A-Za-z=.]//g; # delete "Pending", "=" and "." $data[1] =~ s/\..*//g; # delete the millisecond element of the + (line)lTime var my @lTime=split(/:/,$data[1]); # split the line time my $lSecs=$lTime[0] * 3600 + $lTime[1] * 60 + $lTime[2]; # con +vert line-time to seconds if (($data[0] eq $ymd) && ($data[10] >= $tHold) && ($lSecs >= +$sSecs) && ($lSecs <= $eSecs)) { $line = "$data[1],$data[10]"; } }

I — think — you may be trying to load each line of the file into an array, then match the records you want? (I don't think you need to start out trying to skip unwanted lines. Just match what your looking for from the start.) In terms of your regex matches you could possibly use something like:

m/(?:Pending=)(\d{6})$/ # If you want the number after 'Pending'. m|\s(\d\d:)+(\d){2}\.(\d){3}\s| # To match the time stamp.

These are just some ideas but if you could possibly provide a little more clarity that will help much smarter monks help you. :)

 * diagnostics, Data::Dumper

Good luck!


"...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote

In reply to Re: Help with hash of arrays from file by luis.roca
in thread Help with hash of arrays from file by jb60606

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.