G'day Monks,
I am for the first time trying to understand how to hash hashes but I am not getting it...seems I don't have enough nerve cells firing correctly to get it from the meager examples I have seen...I have a set of data that in a specific format which I have included a sample below...then below it is my first attempt to understand the proper format of how to code a multi layered associative array...but I can't even get pass the syntax error on line 32 where I am trying to define the associative array...if I could get help just understanding the proper repeatable tree to build a multi layered associated array it would be GREATLY appreciated...thanks for your attention and help in advance.
Data Set:
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
Code Attempt - my idea is to create a hash called %host where $inst (Disk Instance) is the key along with the $count (Number of Data Points) where Instance.Count are the key to each key of dayofweek, month, date, timing, year, dpoint...if I am over thinking this or completely missing the obvious please someone slap me so I understand...and thanks may I have another?
:-)
#!/usr/local/bin/perl
use Data::Dumper;
use strict;
# filename like wspmon03.DSKAvgServ.log
my $filename = $ARGV[0];
(my $hostname, my $parameter) = split("\.", $filename, 2);
open(FDAT, $filename) || die "Can't open file: $filename - $!\n";
my $count = 0;
my $inst = "";
my $previous_inst = "dummy";
while(<FDAT>)
{
if (/.*\/DISK\.(.*)\/.*/)
{
my $inst = $1;
}
else
{
if ($previous_inst ne $inst)
{
$count = 0;
$previous_inst = $inst;
}
(my $dayofweek, my $month, my $date, my $timing, my $year, my
+$dpoint) = split();
my %host ( $inst, $count => { 'dayofweek' => $dayofweek, 'mon
+th' => $month, 'date' => $date, 'timing' => $timing, 'year' => $year,
+ 'dpoint' => $dpoint } );
$count=$count+1;
}
}
print Dumper(%host);
close (FDAT);
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.