Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: $1 not "freezing" in an addition

by Anonymous Monk
on Dec 14, 2012 at 12:27 UTC ( [id://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(); $

Replies are listed 'Best First'.
Re^2: $1 not "freezing" in an addition
by grondilu (Friar) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1008825]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-03-29 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found