in reply to can't use string refs while "strict refs"
Perhaps something like this:
use strict; use warnings; my $x = "Mmm...donut, thought Homer"; if (my @matches = $x =~ /^(Mmm|Yech)\.\.\.(donut|peas)/) { unshift @matches => undef; foreach my $expr (1..$#-) { print "Match $expr: '$matches[$expr]' at position ($-[$expr],$ ++[$expr])\n"; } }
Note the trick is to capture the return value of the =~ into an array (which I've called @matches above).
Trick number two is to unshift a dummy value into $matches[0]. This is because arrays are indexed from 0 and regex matches are numbered from 1. Unshifting the dummy value makes @matches line up better with $- and $+.
|
|---|