The problem is the spaces you have around $position in the grep, as illustrated by the following test code:
my @priority = qw/RB1 RB2 FL1 FL2 QB1 QB2 TE1 WR1 WR2 DST/; my $position = q{QB2}; # Print original list print join q{ }, @priority; # Process using original regex, with spaces @priority = grep {!/ $position / } @priority; print join q{ }, @priority; # Process using regex with spaces removed @priority = grep {!/$position/ } @priority; print join q{ }, @priority;
Output:
RB1 RB2 FL1 FL2 QB1 QB2 TE1 WR1 WR2 DST RB1 RB2 FL1 FL2 QB1 QB2 TE1 WR1 WR2 DST RB1 RB2 FL1 FL2 QB1 TE1 WR1 WR2 DST
An alternative might be the /x regex modifier, which tells the regex parser to ignore most non-backslashed, non-character class whitespace.
Hope that helps.
In reply to Re: Grep & Regex Question
by atcroft
in thread Grep & Regex Question
by jdlev
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |