Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm no internals wizard, but I think you're right on the mark.

But more importantly, this is the correct behavior. The purpose of the warning is (presumably) a second line of defense behind strict, for detecting a mispelled variable names. It's purpose probably isn't to warn you that you didn't use it enough, but rather, that not using an undeclared variable means you may (probably do) have a typo.

In the case of a my declared variable, You'll actually still get the warning if you typo it OTHER THAN in the my call. But if you're using my... shouldn't you also be using strict? I am curious as to the thought process that would lead to using only one of the two.


perl -we 'my $foo; $fooo = 42' Name "main::fooo" used only once: possible typo at -e line 1.
Typo was still detected.
perl -we 'my $fooo; $foo = 42' Name "main::foo" used only once: possible typo at -e line 1.
Typo still detected.
perl -we 'my $fooo;'
No warning. If it is a typo is questionable. It is like a program with no output; if it DOES anything is a matter for some philosophers. But it doesn't matter. Declaring an extra my var doesn't hurt anything. And if you group all your my calls together like my( $foo, $bar, $baz, ) then it doesn't even waste much time. On many systems, I doubt the difference would be measurable.

And so even in all the examples given prior, the correct behavior of identifying harmful typos is always taken.

Personally, I think it's terrible to write code without strict, when it's code that is important enough, or will last long enough, or is intricate enough, that warnings are needed or used. I would only recommend forgoing use strict on once-off one-liners (ie, system administration and playing around).

Snazzy tagline here

In reply to Re^2: How do I find out which variables I'm not using? by Aighearach
in thread How do I find out which variables I'm not using? by amyoungil

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-06-21 21:39 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.