http://qs1969.pair.com?node_id=220161


in reply to Re: Re: pos()atively mysterious.
in thread pos()atively mysterious.

The documentation for pos explains this behaviour - Where a variable is not specified as the first argument to the pos function, the match offset is attempted against $_.

In the example code that you provide, you are matching against the variable $str while trying to find the match offset against the default variable $_, which naturally returns an undefined error. If you update the code to either match against the variable $_ or return the match offset against the variable $str, your code will execute as expected.

 

perl -le 'print+unpack("N",pack("B32","00000000000000000000000111111010"))'

Replies are listed 'Best First'.
Re: Re: Re: Re: pos()atively mysterious.
by BrowserUk (Patriarch) on Dec 16, 2002 at 11:01 UTC

    Ah so! Grasshopper. Thanks++

    No matter how many times I read

    Returns the offset of where the last m//g search left off for the variable in question.

    I never took in the significance of those last 5 words.

    Makes sense (now:), if was just the last position matched by the last m//g which was how I was reading it, there would be no need for a function; a $var would do.

    D'oh!


    Examine what is said, not who speaks.