in reply to regexp and substitute operator problem
It will fail to check the next item after each match. It's much simpler (and correct-er) to write:my @arr = qw/ foo foozle bar bar2 foo bar foo /; for (my $i=0; $i<@arr; $i++) { splice(@arr, $i, 1) if ($arr[$i] =~ /bar/); } print "$_\n" for (@arr); ## output: bar2 is NOT removed
Although, if you're dealing with a huge amount of genetic data, this will be very slow. A quick fix to the existing loop would be the slight change:@chroms = grep { ! /[pqxy]/i } @chroms;
This still may not be optimal, but it's in-place so should be faster than the grep.for (my $i=0; $i<@chroms; $i++) { splice(@chroms, $i--, 1) if not $chroms[$i] =~ /[pqxy]/i; } ####
About your second question... Off the top of my head, I'm not sure what's up with your regex... It's late for me!
blokhead
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: regexp and substitute operator problem
by dannoura (Pilgrim) on Jul 08, 2003 at 06:28 UTC | |
by Dog and Pony (Priest) on Jul 08, 2003 at 06:37 UTC |