Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: add data to HoA

by Riales (Hermit)
on Feb 07, 2012 at 22:21 UTC ( #952374=note: print w/ replies, xml ) Need Help??


in reply to Re^2: add data to HoA
in thread add data to HoA

You'd have to push each element of @days_between onto each of the arrays in $GSPmsgHash like so:

push @{$GSPmsgHash{$date1}}, $days_between[0]; push @{$GSPmsgHash{$date2}}, $days_between[1];

You'd have to figure out the respective keys ($date1 and $date2) you'd need for each of the values in @days_between so you can add the right value to the right array.


Comment on Re^3: add data to HoA
Select or Download Code
Re^4: NOT seeing data in HoH
by dbs (Sexton) on Feb 08, 2012 at 21:49 UTC
    I decided to change my code around a bit, so now I am not seeing a value in my HoH when I print normally, but when I print using Data Dumper I see it??? The item I am NOT seeing is the number 3 under __OUT__. Help! thnkU!
    __DUMPER OUT__ $VAR1 = { DATE: 01/20/2012 TIME: 21:12:38 ' => { ALERT LEVEL: 6 = Boot possible, pending failure - action required SOURCE: 4 = power ', SOURCE DETAIL: 4 = high voltage DC power SOURCE ID: FF PROBLEM DETAIL: 7 = illegal power supply type ', '19' => ' Days Bet +ween Today and last Alert' }, DATE: 02/05/2012 TIME: 07:50:19 ' => { SOURCE DETAIL: 0 = unknown, no source stated SOURCE ID: FF PROBLEM DETAIL: 0 = no problem detail ', '3' => ' Days Betw +een Today and last Alert', ALERT LEVEL: 2 = Non-Urgent operator attention required SOURCE: 0 = unknown, no source stated ' } }; __OUT__ # perl HPMP_mark3_parselogs.plx DATE: 01/20/2012 TIME: 21:12:38 ==> ALERT LEVEL: 6 = Boot possible, pending failure - action required SOURCE: 4 = power SOURCE DETAIL: 4 = high voltage DC power SOURCE ID: FF PROBLEM DETAIL: 7 = illegal power supply type 19 Days Between Today and last Alert DATE: 02/05/2012 TIME: 07:50:19 ==> SOURCE DETAIL: 0 = unknown, no source stated SOURCE ID: FF PROBLEM DETAIL: 0 = no problem detail ALERT LEVEL: 2 = Non-Urgent operator attention required SOURCE: 0 = unknown, no source stated __ACTUAL_CODE__ use strict; use warnings; use FileHandle; use MIME::Lite; use Date::Calc "Delta_Days", "Today"; my $RLOG = new FileHandle "+< $Rawlog" or warn "Open failed: $!"; my (@ary, $recordcount, $alert4orMoreCount, @attnlight, $dateofalert, @dateofalert, $arranged, $days_between, @days_between, $attnlightcount, @dates, $alert3orLessCount, %GSPmsgHash, $date, $alertLv, $src, $srcD, $pr +obD ); my ( $year,$month,$day ) = Today(); while (<$RLOG>) { if (/(Log Entry\s\#.*)/) { ++$recordcount; my $log = $1 .+ "$RTF{ln2}"; my $sys = <$RLOG>; $date = <$RLOG>; $alertLv = <$RLOG>; <$RLOG>; $src = <$RLOG>; $srcD = <$RLOG>; $probD = <$RLOG>; <$RLOG>; my $callerA = <$RLOG>; my $callerAS = <$RLOG>; my $rptEnt = <$RLOG>; <$RLOG>; my $hex1 = <$RLOG>; my $hex2 = <$RLOG> .+ "$RTF{ln}=========================== +==============="; push @ary, ($log,$sys,$date,$alertLv,$src,$srcD, $probD,$callerA,$callerAS,$rptEnt,$hex1,$hex2 ); if (/(LEDs:\s+RUN.*)/) { my $attnlight = <$RLOG>; push @attnlight, (split(" ", $attnlight, 0))[1]; } $dateofalert = ((split (" ", $date, 0))[1]); $dateofalert =~ y /\///d; $arranged = substr( $dateofalert, -4, 4 ) . substr( $dateof +alert, 0, 4); my $yyyy = substr( $arranged, 0, 4); my $mm = substr( $arranged, -4, 2); my $dd = substr( $arranged, -2); $days_between = Delta_Days($yyyy, $mm, $dd, $year, $month, $da +y); $GSPmsgHash{$date} = { $alertLv, $src, $srcD, $probD, $days_between, ' Days Between Today and last Alert', } } } $RLOG->close; while ( my ($k, $v) = each(%GSPmsgHash) ) { print "\n$k ==>\n",%{$v},"\n"; }
      If you're going for a HoH, you'll need keys for each value in the inner hash (like you're using $date as a key in the outer hash). Instead of:
      $GSPmsgHash{$date} = { $alertLv, $src, $srcD, $probD, $days_between, }
      You probably want:
      $GSPmsgHash{$date} = { alert_level => $alertLv, source => $src, source_detail => $srcD, problem_detail => $probD, days_between => $days_between, }
      This way, to get the alert level for $date, you would do the following:
      my $alert_level = $GSPmsgHash{$date}->{alert_level};
        OK I can make that work the way you showed, but I am still wondering why days_between only shows up when I use Data::Dumper. Nevermind I got it working: with: Thx agn!
        for my $k (keys %GSPmsgHash) { print "$k =>\n"; for my $v (values %{$GSPmsgHash{$k}} ) { print " $v\n"; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://952374]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (17)
As of 2015-07-01 17:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (12 votes), past polls