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

Hello alll, i have to extract all information from one timing report using hash.. so i use regexp and hash and i got the output from the help of these foram but there is one dout pls go through my code ..

#!/usr/bin/env perl use strict; use warnings; use autodie; my $report_file = 'pm_1080084_timing_manual.rpt'; my %PG; local $/ = "\nStartpoint"; open my $fh, '<', $report_file; while (<$fh>) { /[(](\w+)[^(]+[(](\w+)[^:]+:\s+(\w+).*?slack[^-]+(-\d+)/s; $PG{$3}{"$1-$2"} = $4; } use Data::Dump; dd \%PG; -------------------------------------------------------- This outputs -------------------------------------------------------- { PLBCLK => { "input-output" => -4, "rising-output" => -3 }, PLBCLK1 => { "input-rising" => -1, "rising-rising" => -2 }, } *********************************************************** 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 clock network delay (ideal) 0.00 0 +.00 PLB4ARB8M_ARB_TOP1/reg_PLB_pacr_reg[2]/CLK (DFFX1) 0.00 0 +.00 r 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

From these timing report all information is extracted and its shown in output... but now i have some chages in timing report .. there is some spaces at the strating of the Startpoint line.. belove is the modified timing report..please help me out for same what i need to chage in my Regexp line..

*********************************************************** modified 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 clock network delay (ideal) 0.00 0 +.00 PLB4ARB8M_ARB_TOP1/reg_PLB_pacr_reg[2]/CLK (DFFX1) 0.00 0 +.00 r 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

please help for these..what change i need to do in my code? thanks for your time!

Replies are listed 'Best First'.
Re: regexp with Hash dout
by InfiniteSilence (Curate) on Apr 10, 2014 at 14:35 UTC

    When I push the timing files to separate files and run each of them against your script using the debugger I notice that it runs twice for the first file but only once for the second:

    main::(working.pl:11): while (<$fh>) { DB<1> main::(working.pl:12): /[(](\w+)[^(]+[(](\w+)[^:]+:\s+(\w+).*?s +lack[^-]+(-\d+)/s; DB<1> main::(working.pl:13): $PG{$3}{"$1-$2"} = $4; DB<1> main::(working.pl:12): /[(](\w+)[^(]+[(](\w+)[^:]+:\s+(\w+).*?s +lack[^-]+(-\d+)/s;

    Simple analysis of what is in $_ immediately after Line 11 reveals that it contains everything up to the second record. With the second timing file the same thing shows you the entire file. Therefore, your record separator is not matching correctly. If you change your code to the following it should work:

    my $report_file = $ARGV[0]||'timing_report.rpt'; my %PG; local $/ = "Startpoint"; open my $fh, '<', $report_file; while (<$fh>) { if(/[(](\w+)[^(]+[(](\w+)[^:]+:\s+(\w+).*?slack[^-]+(-\d+)/s) { $PG{$3}{"$1-$2"} = $4; } } use Data::Dump; dd \%PG;

    You'll notice that I made two changes to your code. 1) I changed the record separator from "\nStartpoint" to just "Startpoint" and 2) I wrapped your regular expression in an if statement.

    My recommendations for you going further are as follows:

    • Spend more time learning how to use the Perl debugger and walking through your code to see what is actually happening.
    • use the /x modifier when writing long regular expressions so that you can break them out and make them easier to read.

    Celebrate Intellectual Diversity

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: regexp with Hash dout
by ww (Archbishop) on Apr 10, 2014 at 17:43 UTC
    See [untitled node, ID 1080191], and replies, posted under a different user name.

    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!