Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by Wysardry (Pilgrim)
on Feb 02, 2003 at 23:53 UTC ( [id://232088]=note: print w/replies, xml ) Need Help??


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

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).

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

Replies are listed 'Best First'.
Re: Re: Re: Using "my" suppresses "Name used only once" warning?
by Marza (Vicar) on Feb 03, 2003 at 00:04 UTC

    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).

        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).
        /me gives Wysardry the odd look.

        You mean the Hungarian notation? You can do that in Perl just as well. In fact, there's no requirement in those other languages that the type inferred from your conventional prefix actually agrees with the actual declared type. Nothing prevents you from declaring an integer strFoo or a string pointer iBar. Because it's only a convention.

        If you really feel the need for this kind of "self-documentaion", go ahead. Nothing is stopping you.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-23 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found