Keep It Simple, Stupid | |
PerlMonks |
Re^3: $1[ (or "Does an array @1 exist in Perl ? - Yes!")by davido (Cardinal) |
on Oct 11, 2017 at 15:52 UTC ( [id://1201171]=note: print w/replies, xml ) | Need Help?? |
The fact that $1 is a pre-declared variable, and that @1 is not does not mean that @1 could not have been a variable, and consequently, that $1[... should not be seen as the beginning of an indexing into the @1 array. It really probably ought to be a strict violation first, since @1 isn't special, but is an identifier, and subject to the rules of parsing that apply to sigil-preceded identifiers when interpolated into a regexp quote-like construct.
Here we cheated a little, using the typeglob syntax to create an array by the name of @1. Well, really a symbol for an array named @1, which happens to be an alias to @array in the symbol table. And it is shown to work. With that in mind, there's no reason that m/something$1[.../ should not be seen as the beginning of the indexing into an array element for interpolation within a regexp. Disambiguation can be achieved by wrapping the symbol portion of $1 in curly braces, as in ${1}:
Otherwise, this will be variable interpolation:
The unfortunate part here is that strict appears to be special cased for the numeric-variable symbols rather than specifically for scalars. Dave
In Section
Seekers of Perl Wisdom
|
|