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

Evaluating a match operator in list context will return a list of the contents of the match's captures. Example:

my $string = 'abcde'; my @captures = $string =~ m/.(.)(.)(.)./; print "$_\n" for @captures; __END__ b c d

What I think you're attempting to construct is a symbolic reference named by user input. That's a bad idea, as the user could access any global variable in your program, intentionally or unintentionally. Just capture into an array as demonstrated above.


Dave

Replies are listed 'Best First'.
Re^2: Is there an array for $1,$2,$3... or some alternative ?
by palkia (Monk) on Mar 14, 2012 at 04:57 UTC
    Don't worry, the user was only able to enter a positive integer (anything else if rejected ^^)
    Any way your solution worked gr8, thx.

    Looking back now, I should've know it returns a list of matches, considering I learned long ago (by experimenting), that it returns the number of matches (in scalar context),
    So I've earned myself some mto point ^^
    Thx again