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

Re: Using "my" suppresses "Name used only once" warning?

by Marza (Vicar)
on Feb 02, 2003 at 23:15 UTC ( [id://232074]=note: print w/replies, xml ) Need Help??


in reply to Using "my" suppresses "Name used only once" warning?

Why yes it does.

Using the strict module forces you to declare variables lexically (using my $var) and belong to a block or file, or be declared globally.

When it is declared to a block of code(ie sub), I guess the value of "used once" is no longer issue as the value disappears after the sub has completed.

A global declaration well the same thing comes to play but they disappear at programs end.

Mind you that is how I understand it. If I am wrong one of brothers will surely correct me! ;-)

  • Comment on Re: Using "my" suppresses "Name used only once" warning?

Replies are listed 'Best First'.
Re: Re: Using "my" suppresses "Name used only once" warning?
by Wysardry (Pilgrim) on Feb 02, 2003 at 23:53 UTC

    Well, I'm not really concerned if a variable is truly only used once, but more if it isn't used at all.

    Unfortunately, the act of using "my" in declaring a variable ready for use - even without setting a value - is counted as using it, which seems a little odd.

    I was hoping to be able to be warned if I'd declared a variable and then not used it for anything. This might happen if I removed a section of code, or declared a lot of variables at once in the early stages of coding, but then decided not to (or just plain forgot to) use one of them later in the development process.

    Oh, by the way, it isn't the strict pragma that's causing this - it is my (I tried this without strict, but with my).

      Oh I know that. I used the strict description as you will hear "use strict" chanted to newbies all the time. When you use strict, you have to declare the variable (ie my) which in turn causes your situation.

        I kind of figured you'd realised it wasn't strict that was the cause, I was really adding something I forgot to mention in my first post.

        I actually want Perl to complain to me, so I sought out the strict pragma even before I started reading advice to use it.

        I've spent a lot of time modifying other people's programs, and now that I'm writing my own code I need a little help from Perl so that I don't need to keep looking things up in the documentation.

        Perl is also the only language I've used seriously that doesn't have strong type casting, which worries me a little at times. I guess I'm used to being able to tell whether a variable is a number or a string just from the prefix character (which is handy when reading unfamiliar or forgotten code).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found