in reply to On quoting the lhs of '=>'

You're spending a lot of time on something that just isn't worth it. The performance gain from the constant pragma is never going to tip the balance in a real world application, and the problem only gets worse when you need to use them in double-quoted strings. Use a normal variable:

our $BIRD = 'Valery';

Replies are listed 'Best First'.
Re^2: On quoting the lhs of '=>'
by tinita (Parson) on Jul 10, 2008 at 12:10 UTC
    The performance gain from the constant pragma is never going to tip the balance in a real world application
    One optimization alone is never going to tip the balance. but imagine how slow perl scripts would be if *everybody* thought like that.
    i use a constant to switch on and off debugging in one of my modules, and i compared it to a normal variable, and the difference was big enough for me to use a constant. and as i'm doing benchmarks quite regularly i think i can estimate that.
    i'm so tired of all the people saying "don't optimize prematurely" while i have to use several awfully slow tools at work. and slow forums like this one. yes, don't optimize too early, but do it at least at *some* point.
    i just don't see why using a constant would be bad at all. trading speed for maintainability is usually not worth it, but what's wrong with a constant. just learn what you have to do if you use it as a hash key and in strings, and that's it.
      There are optimizations and there are optimizations. This one isn't worth it, except in special cases. You may have a special case with your debugging example.

      The problem with constant is just what you said: maintainability. Over the years, I have seen so many people have problems with the constant module that I consider it a frequent source of bugs. Yes, if you learn all the details of using it in hashes and strings you can make it work, but people "constantly" stumble over it. It's just too error-prone.

Re^2: On quoting the lhs of '=>'
by ikegami (Patriarch) on Jul 09, 2008 at 19:35 UTC
      Honestly, I don't see the point. Are you trying to guard against accidental assignment? It doesn't seem worth the trouble to me.

        To guard and, equally importantly, to show in the code that this is an entity which is defined, but not going to be changed. Maybe it is because I always feel a bit uncomfortable with the idea of a variable which changes the value over the time. I feel more at home in the realm of functional programming, where you don't have assignment statements which modifiy the content of a variable.

        Of course this is personal taste, but I still find it good practice to make clear in the code when an entity is supposed to be a constant.

        -- 
        Ronald Fischer <ynnor@mm.st>