Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by Marza (Vicar)
on Feb 03, 2003 at 00:04 UTC ( [id://232093]=note: print w/replies, xml ) Need Help??


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

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.

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

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

    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.

        Well, I'm not sure whether it's called Hungarian notation or not, but in BASIC for example, a string variable name is prefixed with a $ character, integers start with % and floating point numbers have no prefix.

        That way, you can have 3 different variables called $x, %x and x and know what type of value they can contain (even though "x" tells you little else).

        Trying to give a value in the wrong format, such as adding 0.5 to an integer, would cause a "type mismatch" error.

        Okay, so maybe that restriction does force you to do unecessary conversions at times, but those prefixes do make it easier to debug unfamiliar code.

        It also makes it more obvious what type of value a particular subroutine is expecting to have passed to it if you want to reuse it elsewhere.

        I'm sure I can find some way to make it clearer what type of value my variables are intended to be used with. I was just hoping there was some way to have that checked every once in a while during development.

        There have been plenty of good suggestions given to help anyway. :o)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-18 04:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found