XP is just a number | |
PerlMonks |
Is there a default array for reg exp memory variables?by korpenkraxar (Sexton) |
on Feb 05, 2012 at 22:16 UTC ( [id://951996]=perlquestion: print w/replies, xml ) | Need Help?? |
korpenkraxar has asked for the wisdom of the Perl Monks concerning the following question: Dear wise bringers of enlightenment Reg exp patterns stored in variables can specify arbitrary numbers of matching substrings and create a dynamic number of memory variables. Is there a default array that contains $1, $2, $3 ... that we can return from a reg exp rather than specifying the individual memory variables? I have searched the interwebs but uncovered nil indicating its existence :-( Consider this case:
In the first two cases I resorted to hard-coding the number of memory variables and setting it to some sort of theoretical maximum to cover all expected cases, which leads to the creation of uninitialized elements in the array since the pattern is short. In the last two cases I do the matching in list context which works very neatly. Perl is obviously smart enough to build an array for us in this case. Can we get hold of that array explicitly somehow when we are not in list context?
Back to
Seekers of Perl Wisdom
|
|