Hey hbm, thanks for the reply.

I tried reading the data into the hash at first but it was just confusing the crap out of me (trying to use @_ or $_ and also $line) so I did the array thing just to get myself started. Once I get more comfortable with hashes, most likely by the end of this, I will probably go back and change it to what you suggested.

haha Yeah your right, I guess it is pointless to use "join" when only joining 2 elements. Good point, thanks.


I was working on this thing below that I am kinda stuck on. Maybe you could see what I am not doing right.
What I want to do is: I have this new SUB, also a new array (@colLens used this method before with a 2D-Array and it worked good). @colLens has 0..7 elements, same as the amount of fields per each record.

What it will do is, loop through the hash and if the current hash element's length is greater than the value in the same position in @colLens, then that element in @colLens will now big the bigger of the two. So the end effect will be that @colLens holds the largest length of each hash element 0..7 .


Here's what I tried:
my @header = ("RECORD_ID", "STATUS", "PID", "TIME", "DATE", "HELD/WAIT +ING", "FILENAME", "USER"); my @colLens; sub getColumnLengths() { for (my $y = 0; $y <= $#header; $y++) { $colLens[$y] = length($header[$y]); } my $x; # $rec1 = RECORD_ID for my $rec1 ( keys %records ) { $x = 0; if (int($colLens[$x]) < length($rec1)) { $colLens[$x] = length($rec1); } # $rec2 = STATUS for my $rec2 ( keys %{ $records{$rec1} } ) { $x = 1; if (int($colLens[$x]) < length($rec2)) { $colLens[$x] = length($rec2); } $x++; # $rec3 = PID, TIME, DATE, ELAPSED, FILENAME, USER for my $rec3 ( keys %{$records{$rec1}{$rec2}} ) { if (int($colLens[$x]) < int(length($rec3))) { $colLens[$x] = int(length($rec3)); } $x++; }#END INNER-MOST }#END MID }#END OUTER }

From my output I get it seems that it is working for just the first 2 elements, not sure why the rest isn't? I'm assuming it is something with my inner-most loop...


If you can think of anything please let me know.

Thanks in Advance,
Matt

In reply to Re^5: Perl Hashes, keys under keys (I think)? by mmartin
in thread Perl Hashes, keys under keys (I think)? 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.