mak.jordan has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, here i aatch my code please go through it i extract all data from one of my log file and put it into one hash but cant access that data in foreach loops..
open (INFILE1,"timing_manual.rpt"); my %PG; use Data::Dumper qw(Dumper); local $/ = "Startpoint"; while(<INFILE1>){ /[(](\w+)[^(]+[(](\w+)[^:]+:\s+(\w+).*?slack[^-]+(-\S+)/s; $PG{$3}{"$1-$2"}{$cou} = $4; $cou++; } print Dumper \%PG ; foreach $path1 ( keys %PG ) { foreach $path2 (keys %{$PG{$path1}} ) { foreach $path3 ( keys %{$PG{$path1{$path2}}} ) { + foreach $path4 (keys %{$PG{$path1{$path2{$path3}}}}) { print "$path1 \t $path2 \t + $path3 \t $path4\n"; } } } } *********************************************************** TIMING REPORT FROM WHERE I WANT EXTRACT ALL INFO. *********************************************************** Startpoint: PLB4ARB8M_ARB_TOP1 (input port edge-triggered flip-flop clocked by PLBCLK1) Endpoint: PLB4ARB8M_ARB_TOP1/reg_PLB_WrBusControlStates_reg[9] (rising edge-triggered flip-flop clocked by PLBCLK1) Path Group: PLBCLK1 Path Type: max Point Incr P +ath -------------------------------------------------------------------- +------ 0.00 2 +.80 r library setup time -1.54 1 +.26 data required time 1 +.26 -------------------------------------------------------------------- +------ data required time 1 +.26 data arrival time -3 +.24 -------------------------------------------------------------------- +------ slack (VIOLATED) -1 Startpoint: PLB4ARB8M_ARB_TOP1/reg_PLB_pacr_reg[2] (rising edge-triggered flip-flop clocked by PLBCLK1) Endpoint: PLB4ARB8M_ARB_TOP1/reg_PLB_pesr_reg[10] (rising edge-triggered flip-flop clocked by PLBCLK1) Path Group: PLBCLK1 Path Type: max Point Incr P +ath -------------------------------------------------------------------- +------ clock PLBCLK1 (rise edge) 0.00 0 +.00 clock network delay (ideal) 0.00 0 +.00 -------------------------------------------------------------------- +------ data required time 2 +.73 data arrival time -3 +.65 -------------------------------------------------------------------- +------ slack (VIOLATED) -2 Startpoint: PLB4ARB8M_ARB_TOP1/reg_PLB_pacr_reg[2] (rising edge-triggered flip-flop clocked by PLBCLK1) Endpoint: PLB4ARB8M_ARB_TOP1 (output port edge-triggered flip-flop clocked by PLBCLK1) Path Group: PLBCLK Path Type: max Point Incr P +ath -------------------------------------------------------------------- +------ clock PLBCLK1 (rise edge) 0.00 0 +.00 data arrival time -3 +.24 -------------------------------------------------------------------- +------ slack (VIOLATED) -3 Startpoint: CPU_DCRADDR[8] (input port clocked by DCRDATA) Endpoint: PLB_DCRDATA[9] (output port clocked by DCRDATA) Path Group: PLBCLK Path Type: max Point Incr Path ----------------------------------------------------------- clock DCRDATA (rise edge) 0.00 0.00 ----------------------------------------------------------- data required time 1.14 data arrival time -1.46 ----------------------------------------------------------- slack (VIOLATED) -4
Above here i shows some of timing paths but actually in timing report there are thousands of paths are present.. Please help me out how i can my hash data to further ?? Thanks for your time!! :)

Replies are listed 'Best First'.
Re: How to get my hash data using foreach loop??
by Ratazong (Monsignor) on Apr 11, 2014 at 12:59 UTC

    Hi mak.jordan!

    Here are few observations on your code:

    1. Looking at

    $PG{$3}{"$1-$2"}{$cou} = $4;
    you have three levels of keys in your hash. Therefore you only need three loops for accessing your data. Your innermost data ($4) is the value, not a key. So you should get rid of the innermost foreach loop.

    2. A hint on debugging: it is much easier to develop the access of the hash step by step: First only write the outmost loop and check if the keys are teh ones that you are expecting. In the second step you add the second level, and check if the loop is working as expected (with a print statement) and so on. Then you'll find out where your code is wrong.

    3. Having done this, you'll probably notice an error in the following line:

    foreach $path3 ( keys %{$PG{$path1{$path2}}} )
    Using $PG{$path1{$path2}}, you try to use $path1 as a hash, using the key $path2. And use the value of that hash-lookup as first-level-key in PG. However you want to access the second level of the $PG-hash. That would be done with $PG{$path1}{$path2}

    HTH, Rata