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

Re^2: Infinite regex loop...

by tj_thompson (Monk)
on Jun 29, 2011 at 22:01 UTC ( #912047=note: print w/replies, xml ) Need Help??

in reply to Re: Infinite regex loop...
in thread Infinite regex loop...

Your code, for the most part, seems to do what you want. I don't see how you can end up in a loop. The only portion that seems very suspect is this:

if ($SIRtrue && !($_ =~ /SPECint_base/)){ $SIR{$_}=$_; } if ($SFRtrue && !($_ =~ /SPECfp_base/)){ $SFR{$_}=$_; }

You're stuffing the line you find into a hash key named the same as the line value. This is likely not what you want.

This may be closer to what you want (assuming my data below somewhat resembles your file), but it's honestly hard to say:

use strict; use warnings; use Data::Dumper; my $str = <<END; SPECint_base 1 2 3 SPECfp_base 4 5 6 END open my $fh, '<', \$str or die "Could not open for read:$!\n"; my $SIRtrue; my $SFRtrue; my %SIR = (); my %SFR = (); while (<$fh>){ chomp; if (/SPECint_base/){ $SIRtrue = 1; $SFRtrue = 0; next; } elsif (/SPECfp_base/){ $SIRtrue = 0; $SFRtrue = 1; next; } if ($SIRtrue)){ push( @{$SIR{SPECint_base}}, $_ ); } elsif ($SFRtrue){ push( @{$SFR{SPECfp_base}}, $_ ); } } print Dumper(\%SIR); print Dumper(\%SFR);


$VAR1 = { 'SPECint_base' => [ '1', '2', '3' ] }; $VAR1 = { 'SPECfp_base' => [ '4', '5', '6' ] };

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://912047]
[Eily]: what error? I see no issue :P
LanX and: = harder to reproduce. ..
[LanX]: sorry, i didn't break math yet, but it's top priority on my todo list
[choroba]: does your list start with number 5?
[LanX]: -i
LanX it's an imaginary list ...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2018-03-20 10:22 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (249 votes). Check out past polls.