Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: Global variable unexpectedly modified when passed by reference

by BrowserUk (Patriarch)
on Dec 10, 2014 at 02:32 UTC ( [id://1109839]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Global variable unexpectedly modified when passed by reference
in thread Global variable unexpectedly modified when passed by reference

You know, hidden away in all the pointless hieroglyphics, verbose irrelevancies, overly complicated example, and cutesy catch phrases, there is actually the glimmer of an arguable point:

the language-system “raised no ‘quibble’ at all.”

Isolated and translated, if you'd said: "Perl doesn't raise a warning when you use a reference in a numeric context; and that has caught me out.", then you might at least have engendered some reasonable discussion on a potentially valid point.

And so, just for you, here it is:

C:\test\perl-5.18.0>.\perl -E"say 0+$_ for \( 1, 'fred', $^O, @a, %h)" Reference used in a numeric context at -e line 1. 10473656 Reference used in a numeric context at -e line 1. 10474016 Reference used in a numeric context at -e line 1. 10845904 Reference used in a numeric context at -e line 1. 10845952 Reference used in a numeric context at -e line 1. 10848256

Now that needs work. If the reference is held in a variable (as opposed to being use anonymously print \$s + 0;), it'd be nice to list which variable. And the exact text would probably need world+dog approval, along with its warning category; but it could be argued for.

And the change required to make that possible:

C:\test\perl-5.18.0>diff -u sv.c sv.c.modified --- sv.c Wed Dec 10 02:32:20 2014 +++ sv.c.modified Wed Dec 10 02:13:15 2014 @@ -2682,6 +2682,7 @@ if (tmpsv && (!SvROK(tmpsv) || (SvRV(tmpsv) != SvRV(sv)))) return sv_2num(tmpsv); } + Perl_warner(aTHX_ packWARN(WARN_NUMERIC), "Reference used in a + numeric context" ); return sv_2mortal(newSVuv(PTR2UV(SvRV(sv)))); }

That's right. A single added line. (Feel free to take that to p5p and champion it.)

Of course, that raises the question, why if it is so easy to implement, hasn't it been done before? The most likely answer to which is: because no one has found it to be necessary. Till now...?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-18 17:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found