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":



  • 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.