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

hello all, I want to extract information from timing report using hash i done that using regexp..but dont know why one undeclare key is defined??
open (INFILE1,"timing_manual.rpt"); my %PG; use Data::Dumper qw(Dumper); local $/ = "Startpoint"; $temp="abc"; while(<INFILE1>){ /[(](\w+)[^(]+[(](\w+)[^:]+:\s+(\w+).*?slack[^-]+(-\S+)/s; $PG{$3}{"$1-$2"}{"$cou"} = $4; $cou++; } print Dumper \%PG ; ----------------------------Output-------------------------- $VAR1 = { 'PLBCLK1' => { 'rising-rising' => { '2' => '-2.47' }, 'input-rising' => { '1' => '-1.30' } }, '' => { '-' => { '' => undef } }, 'PLBCLK' => { 'rising-output' => { '3' => '-3' }, 'input-output' => { '4' => '-4' } } }; *********************************************************** 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
Here i also attach a timing report from where i extract all the information..in my timing report there are thousands of paths but here i shows some of them.. What the output of my hash shows above.. but i dont want these much undefined part of my hash and why it did place into my hash???
--------------undefined key of my hash--------------- '' => { '-' => { '' => undef } },
Please help me out for these i dont what that much undefined keys or value..Thanks for your time!

Replies are listed 'Best First'.
Re: not defined Hash data came why?
by kcott (Archbishop) on Apr 11, 2014 at 22:02 UTC

    G'day mak.jordan (aka milan.dalwadi),

    The code you're working from is what I provided in "Re^3: How to acess Hash data".

    You've thrown away: strict, warnings, autodie, the 3-argument form of open, the use of lexical variables (except you're retained my %PG), checking for I/O problems and the logical indentation of your code.

    Please go back and read what I said about ignoring advice in that post; the advice I gave you prior to that in "Re: How to acess Hash data"; and the advice other monks have given you (in both your guises as mak.jordan and milan.dalwadi).

    I'm amazed that you ask for our help, ignore it, then ask for our help again. All that's likely to achieve is making us less inclined to help you any further.

    -- Ken

Re: not defined Hash data came why?
by ww (Archbishop) on Apr 11, 2014 at 20:27 UTC
    Since your last three questions all quote (at length!) the same data and (largely) bear on the same issues, perhaps you should:
    1. Read Learning Perl or a comparable primer instead of asking the Monks to create a point by point tutorial, ad hoc. (See On asking for help and How do I post a question effectively?)
    2. Review the available tutorials on this site
    3. Study prior answers for clues on how to answer your current question, notably: use strict; use warnings; insert print (and ADDITIONAL Data::Dumper statements) to help you track what's actually happening in your code; and tell us exactly how you've tried to resolve your problem. That last might give us some further clues in the effort to clear up your blind-spots and misconceptions.

    Also noted: questions on this data-set have been posted under two different user names, milan.dalwadi and mak.jordan. You should be aware the PM frowns on the use of multiple-logins (except for the Gods and a very few, rare exceptions)... and that the persistent questions about a single data sample raise questions about whether this is homework, $work or ??.


    Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
    1. code
    2. verbatim error and/or warning messages
    3. a coherent explanation of what "doesn't work actually means.

    check Ln42!

      Hello, I appolize for these type of question but didnt track the what the error was ... And i am not at that much level in perl what can i do..please help me for these..!!
        The most certain path to "that level" takes you on a course which...
        1. involves YOU making a serious effort to study the advice you've already been given...
        2. and involves YOU reading -- carefully, with an eye to understanding! -- the references you've been given: i.e., put on your learning cap, instead of pursuing the 'spoon feed me" approach.

        Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
        1. code
        2. verbatim error and/or warning messages
        3. a coherent explanation of what "doesn't work actually means.

        check Ln42!

Re: not defined Hash data came why?
by choroba (Cardinal) on Apr 11, 2014 at 19:36 UTC
    Try adding a debug print after the substitution:
    if ($3 eq q()) { warn "<< $.: $_ >>\n"; }

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: not defined Hash data came why?
by AnomalousMonk (Archbishop) on Apr 11, 2014 at 21:45 UTC
    local $/ = "Startpoint"; $temp="abc"; while(<INFILE1>){ /[(](\w+)[^(]+[(](\w+)[^:]+:\s+(\w+).*?slack[^-]+(-\S+)/s; $PG{$3}{"$1-$2"}{"$cou"} = $4; $cou++; }

    The first time you read the record that ends in  "Startpoint" there is nothing in the body of the record (at least, as far as I can see from the posted data). You then parse that data with a regex and add data to the hash regardless of whether or not the parse was valid. Try a modification like (untested):

    my %PG; my $cou = 0; local $/ = 'Startpoint'; RECORD: while (<INFILE1>) { next RECORD unless # unless valid data extracted from record /[(](\w+)[^(]+[(](\w+)[^:]+:\s+(\w+).*?slack[^-]+(-\S+)/s; $PG{$3}{"$1-$2"}{$cou} = $4; $cou++; }

    It would also be wise to check the success of the open statement and die on failure.

    Update: To answer your specific question: When the regex fails to match on the first (malformed) record,  $1 $2 $3 $4 are all undefined, as is $cou. The undefined value stringifies as  '' (the empty string), so you get a hash element of

    --------------undefined key of my hash--------------- '' => { '-' => { '' => undef } },