... what is the index of the first non-space character?
c:\@Work\Perl\monks>perl -wMstrict -le "my $s = ' a '; ;; $s =~ m{ \S }xms; print $-[0]; " 4
... as long as it didn't invoke the regex engine.
What's the point of that?
Update: More generally:
See @- @+ in perlvar.c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'xyzzyBARxkcdFOOyz'; ;; my $vowel = qr{ [AEIOUaeiou] }xms; ;; print qq{offset of first vowel: }, $s =~ m{ ($vowel) }xms ? $-[1] : ' +none'; ;; print qq{offset of last vowel: }, $s =~ m{ .* ($vowel) }xms ? $-[1] : + 'none'; ;; print qq{offset of first vowel: }, 'XYZ' =~ m{ ($vowel) }xms ? $-[1] +: 'none'; " offset of first vowel: 6 offset of last vowel: 14 offset of first vowel: none
Give a man a fish: <%-{-{-{-<
In reply to Re: opposite of index+rindex? How-to? Needed? (updated)
by AnomalousMonk
in thread opposite of index+rindex? How-to? Needed?
by perl-diddler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |