Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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.

Examples:

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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others wandering the Monastery: (6)
    As of 2025-06-24 10:53 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.