Hello choroba,
Thanks for the explanation, and I’m sorry to be obtuse but — I still don’t understand. :-( Consider:
#! perl -l use strict; use warnings; my $s = 'uvXYZdabcXYZfg'; while ($s =~ /(\w\w\w)*?(XYZ)/g) { print 'Found match ', $1, $2, ' at pos: ', pos $s; } print '-----'; while ($s =~ /(abc)*?(XYZ)/g) { print 'Found match ', $1, $2, ' at pos: ', pos $s; }
Output:
22:35 >perl 1476_SoPW.pl Found match abcXYZ at pos: 12 ----- Use of uninitialized value $1 in print at 1476_SoPW.pl line 28. Found match XYZ at pos: 5 Found match abcXYZ at pos: 12 22:35 >
The first capture in each regex is 3 characters wide, but the first regex matches only the second occurrence of XYZ whereas the second regex also matches the first occurrence, with (abc)*? matching zero times. Why the difference in behaviour? In particular, why does (\w\w\w)*? not also match zero times?
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^9: Understanding a portion of perlretut
by Athanasius
in thread Understanding a portion on the Perlretut
by BlueStarry
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |