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:

Celebrate Intellectual Diversity


In reply to Re: regexp with Hash dout by InfiniteSilence
in thread regexp with Hash dout by mak.jordan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.