BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
According to perlop
In scalar context, each execution of m//g finds the next match, returning true if it matches, and false if there is no further match. The position after the last match can be read or set using the pos() function;
But the following snippet
while( 'the quick brown fox' =~ m/(.)/g) { print "Matched '$1' \@ pos:", pos(); }
produces
Matched 't' @ pos:Use of uninitialized value in print at C:\test\temp. +pl line 1. Matched 'h' @ pos:Use of uninitialized value in print at C:\test\temp. +pl line 1. Matched 'e' @ pos:Use of uninitialized value in print at C:\test\temp. +pl line 1. ...
What am I doing wrong?
Examine what is said, not who speaks.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: pos()atively mysterious.
by rob_au (Abbot) on Dec 16, 2002 at 10:33 UTC | |
by BrowserUk (Patriarch) on Dec 16, 2002 at 10:48 UTC | |
by rob_au (Abbot) on Dec 16, 2002 at 10:52 UTC | |
by BrowserUk (Patriarch) on Dec 16, 2002 at 11:01 UTC | |
Re: pos()atively dangerous.
by dingus (Friar) on Dec 16, 2002 at 12:06 UTC | |
by diotalevi (Canon) on Dec 16, 2002 at 14:15 UTC |
Back to
Seekers of Perl Wisdom