in reply to regex problem: doesn't work on the first search but works on the second

You're not showing us any of your input data, but the following certainly works for me:

my $key1 = 'xxx'; my %hash = ( $key1 => { a => 'foo_1_AAAA', b => 'foo_1_BBBB', c => 'foo_1_CCCC', }, ); foreach (sort keys %{$hash{$key1}}) { if ($hash{$key1}{$_}=~ /^.+_(\d+)_.+AAA/gi) { print "found1\n"; } if ($hash{$key1}{$_}=~ /^.+_(\d+)_.+BBB/gi) { print "found2\n"; } if ($hash{$key1}{$_}=~ /^.+_(\d+)_.+CCC/gi) { print "found3\n"; } }
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
  • Comment on Re: regex problem: doesn't work on the first search but works on the second
  • Download Code

Replies are listed 'Best First'.
Re^2: regex problem: doesn't work on the first search but works on the second
by Anonymous Monk on Nov 29, 2013 at 11:48 UTC

    Thanks guys for all the posts. It was very helpful. I am reworking the code now to be more efficient. Thanks again!