in reply to Re: Is there an array for $1,$2,$3... or some alternative ?
in thread Is there an array for $1,$2,$3... or some alternative ?

The user choses both the value of $fromUserNumber and of $pat
when $fromUserNumber in a positive integer !
I wanted that when $fromUserNumber == 1 the line will be
@simMatches = map{$_ =~ s/$pat/$1/} @simMatches;
when $fromUserNumber == 2 the line will be
@simMatches = map{$_ =~ s/$pat/$2/} @simMatches; and so on.

Replies are listed 'Best First'.
Re^3: Is there an array for $1,$2,$3... or some alternative ?
by Marshall (Canon) on Mar 14, 2012 at 06:27 UTC
    When you think of a subset of an array, think grep.
    Use map only when you think of transforming one thing into another.
    Perl variables can be interpolated into a regex expression.
    my $pat = "somepattern"; @simMatches = grep{/$pat$num/} @simMatches; # subset of @simMatches
    Show a couple of lines of actual data and this can all become clear.
    $1 or $2 are regex capture variables that don't seem to play a role here.