Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: $1 not "freezing" in an addition

by Anonymous Monk
on Dec 14, 2012 at 12:27 UTC ( #1008825=note: print w/ replies, xml ) Need Help??


in reply to $1 not "freezing" in an addition

Prove it :)

$ perl -Mstrict -Mwarnings -l junk 13 $ cat junk sub butter { local $_ = 'effect / 7ACV06'; return $1 + junk($_) if s/(\d+)//; } sub junk { local $_ = $_[0]; return $1 if s/(\d+)//; } print butter(); $


Comment on Re: $1 not "freezing" in an addition
Download Code
Re^2: $1 not "freezing" in an addition
by grondilu (Pilgrim) on Dec 14, 2012 at 12:40 UTC

    ok I added the whole code

    PS. Modifying your code, here is a simple version that reproduces the error:

    sub butter { my $_ = shift; return $1 + butter($_) if s/(\d+)//; return 0; } print butter 'effect / 7ACV06';

        "It ought to be easy to recognize an unquoted $1 as a function argument and issue a warning"

        The problem occurs in:

        return $1 + sub_that_does_regex_capturing(...);

        $1 is not a function argument in that. $1 hasn't been a function argument in any of the examples in this thread.

        The problem is writing an expression where one of the operands has a side-effect that can alter the value of another operand. This is very hard to detect through static analysis of source code; it's probably not especially easy to detect at run-time either. Heuristics may be able to catch some common cases.

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008825]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-08-21 16:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (138 votes), past polls