Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Warning about unused lexical variables

by Rhandom (Curate)
on Sep 04, 2007 at 20:20 UTC ( [id://637021]=note: print w/replies, xml ) Need Help??


in reply to Warning about unused lexical variables

At first glance it sounds like a great idea. And it is to a certain extent. But there is an existing system in Perl that does that very thing, although only with global variables.

[paul@paul-laptop nqp]$ perl -we '$x = 1' Name "main::x" used only once: possible typo at -e line 1.

Speaking from experience, this warning has never helped me. It has done the opposite. It has always been a hinderance. It has forced me to write things similar to the following:
my $value = $SOME_PKG::SOME_VAL || $SOME_PKG::SOME_VAL; # warn clean
Arguably, I should have a function in SOME_PKG that returns the value of $SOME_VAL. But there are many existing modules that don't provide accessors.

Use strict catches all of my typos. A warning of this sort never has.

Still - I could see a use for it, but I think I'd want it as an extra-extra pragma:
use warnings qw(single_use_vars);


my @a=qw(random brilliant braindead); print $a[rand(@a)];

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-25 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found