Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: regexp with Hash dout

by InfiniteSilence (Curate)
on Apr 10, 2014 at 14:35 UTC ( [id://1081821]=note: print w/replies, xml ) Need Help??


in reply to regexp with Hash dout

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

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-29 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found