Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The following code is a snippet from a script I'm writing.

When you present us with just a snippet (which we are not able to test ourselves), you run the risk of leaving out relevant details, and it would be more effective to show us a fully self-contained and runnable script (with suitable sample data) to demonstrate the problem. (Usually, in the process of trying to distill the problem into a stand-alone demonstration, you will figure out what the problem is and how to fix it on your own. It generally improves your ability to diagnose problems.)

In the present case, we don't know if maybe you set $/ to undef, and maybe the input file is really big -- in which case, it's probably not the regex that's stalling, but the attempt to read the entire file into a single scalar variable.

Apart from that (or something like that), I don't see anything to indicate a problem with the code as posted, except that there are "cosmetic" issues that could be improved (and cosmetic improvements can be worthwhile) -- e.g.:

use strict; open( FILE, '<', "whatever.filename' ) or die "whatever... $!\n"; my $container; my ( %SIR, %SFR ); while (<FILE>){ chomp; if ( /SPECint_base/ ) { $container = \%SIR; } elsif ( /SPECfp_base/ ) { $container = \%SFR ; } elsif ( $container ) { $container->{$_} = undef; # no need to repeat hash key as has +h value } }
As for trying to debug the process, try running it with 'perl -d' (that is, use the perl debugger), so you can step through it and see where it really gets stuck, and even inspect variables to see whether other parts of the script are doing what you intended.

(Oh, by the way, are you sure that everything following one or the other "header" string should be included in the corresponding container?)


In reply to Re: Infinite regex loop... by graff
in thread Infinite regex loop... by limzz

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-18 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found