You probably don't actually want a hash of hash (HoH), but a HoA. Consider:

use strict; use warnings; use Data::Dumper; my $inst; my %host; while(<DATA>) { if (/.*\/DISK\.(.*)\/.*/) { $inst = $1; next; } my ($dayofweek, $month, $date, $timing, $year, $dpoint) = split; push @{$host{$inst}}, { 'dayofweek' => $dayofweek, 'month' => $month, 'date' => $date, 'year' => $year, 'timing' => $timing, 'dpoint' => $dpoint }; } print Dumper(\%host); __DATA__ wspmon03/DISK.ssd123/DSKAvgServ Wed Nov 30 00:01:27 2006 7.34562 Wed Nov 30 00:02:29 2006 3.31222 Wed Nov 30 00:03:33 2006 1.23511 Wed Nov 30 00:04:23 2006 4.97532 Wed Nov 30 00:05:37 2006 5.31112 Wed Nov 30 00:06:36 2006 6.22991 wspmon03/DISK.ssd126/DSKAvgServ Wed Nov 30 00:01:27 2006 7.34562 Wed Nov 30 00:02:29 2006 3.31222 Wed Nov 30 00:03:33 2006 1.23511 Wed Nov 30 00:04:23 2006 4.97532 Wed Nov 30 00:05:37 2006 5.31112 Wed Nov 30 00:06:36 2006 6.22991 wspmon03/DISK.ssd129/DSKAvgServ Wed Nov 30 00:01:27 2006 7.34562 Wed Nov 30 00:02:29 2006 3.31222 Wed Nov 30 00:03:33 2006 1.23511 Wed Nov 30 00:04:23 2006 4.97532 Wed Nov 30 00:05:37 2006 5.31112 Wed Nov 30 00:06:36 2006 6.22991

Prints:

$VAR1 = { 'ssd129' => [ { 'timing' => '00:01:27', 'dpoint' => '7.34562', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:02:29', 'dpoint' => '3.31222', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:03:33', 'dpoint' => '1.23511', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:04:23', 'dpoint' => '4.97532', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:05:37', 'dpoint' => '5.31112', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:06:36', 'dpoint' => '6.22991', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' } ], 'ssd126' => [ { 'timing' => '00:01:27', 'dpoint' => '7.34562', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:02:29', 'dpoint' => '3.31222', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:03:33', 'dpoint' => '1.23511', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:04:23', 'dpoint' => '4.97532', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:05:37', 'dpoint' => '5.31112', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:06:36', 'dpoint' => '6.22991', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' } ], 'ssd123' => [ { 'timing' => '00:01:27', 'dpoint' => '7.34562', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:02:29', 'dpoint' => '3.31222', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:03:33', 'dpoint' => '1.23511', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:04:23', 'dpoint' => '4.97532', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:05:37', 'dpoint' => '5.31112', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' }, { 'timing' => '00:06:36', 'dpoint' => '6.22991', 'date' => '30', 'month' => 'Nov', 'dayofweek' => 'Wed', 'year' => '2006' } ] };

which has the advantage that you don't need to maintain a bogus item count to 'index' into your 'hash' for the individual server information.

As an aside, your sample code had a nasty bug in it. You redefine $inst inside an if block, assigned a value to it (from $1), then throw the value away when the local instance of $inst goes out of scope at the end of the block.

Update: readmore tags added by popular demand.


DWIM is Perl's answer to Gödel

In reply to Re: How to Hash Hashes by GrandFather
in thread How to Hash Hashes by onegative

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.