Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
$_ = "abcdmefg"; $_ = /m/; print "$&\t$`\t$'\n";
The above printed matched, prematch and after match. But I like to know the position of the charactr 'm' in the string. Then I used while loop like this:It prints: m abcd efg
Then it prints: matched 'm' at 5. Is there anyway to print the position without while loop? I treid to print using pos in the first example, but does not work. Can you pl. help me? Thanks Ashok$_ = "abcdmefg"; while(m/m/g) { print "matched 'm' at ",pos,"\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: position of the last match in RE
by chipmunk (Parson) on Mar 01, 2001 at 08:30 UTC | |
|
Re: position of the last match in RE
by chromatic (Archbishop) on Mar 01, 2001 at 08:30 UTC |