Subsequently, I Googled "perl position of last match" which led me to this which led me to try the following:
Which outputsmy $str = " xyz" print "$str\n"; $str =~ /^(\s*)/g or die; print("match1: pos=", pos($str), "\n"); print "$str\n"; print "@-\n"; print "@+\n"; $str =~ /\G(\s*)/g or die; print("match2: pos=", pos($str), "\n"); print "$str\n"; print "@-\n"; print "@+\n"; $str =~ /\G(\s*)/g or warn; print("match3: pos=", pos($str), "\n"); print "$str\n"; print "@-\n"; print "@+\n";
which I think might help describe what happens...(of course I could be wrong)xyz match1: pos=2 xyz 0 0 2 2 match2: pos=2 xyz 2 2 2 2 Warning: something's wrong at /tmp/Perl-1.pl line 20. Use of uninitialized value in print at /tmp/Perl-1.pl line 21. match3: pos= xyz 2 2 2 2
When \G goes to the position of the previous match to find the next white space, it is already beyond the last position of white space in the string. The warning is sort of uninformative though... . I gotta wonder if the last position and first position being equal leave the \G wondering where to go next?
Am looking forward to other responses to this by those who know...
(yet another opportunity to display my ignorance! Hot Damn!)
In reply to Re: [Perl 5.14, regex]: Problems with /g, \G and pos()
by wjw
in thread [Perl 5.14, regex]: Problems with /g, \G and pos()
by Darkwing
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |