On Thu, Sep 17, 2009 at 14:13, Matteo Riva <mura...@gmail.com> wrote: > On Thu, Sep 17, 2009 at 7:45 PM, Chas. Owens <chas.ow...@gmail.com> wrote: > >> Constants have a value beyond the numbers themselves. Let's suppose >> that there is a non-POSIX system that has a seek function that works >> quite a bit like POSIX seek, but it use different values for beginning >> of file, current location, end of file. If you use literal values in >> all of your calls, you code won't work on that system. If you use >> global variables, then you run the risk of those variables being >> modified accidentally. Constants cannot be easily changed and are >> therefore safer than globals and since they are defined at compile >> time, more flexible than literals. >> >> The fact that you are asking why would you want constants shows that >> you are unfamiliar with the many ways variables are used in >> programming languages. Luckily there was an [article][1] in the >> [Ironman Perl Challenge][2] recently on just that topic. Read that >> article and the ones it references, it will likely make you a better >> programmer. > > Hm no maybe I didn't explain myself: my doubt was not about the use of > constants, but about the "strange" way of defining them. What I thought > when reading it was: "Why not just 'use constant ...' ?". And later "But > how exactly does it work?" I'm now reading perlsub, but it's often > easier to find out the "how does it work" than the "why did he do that". >
Ah, use constant is just sugar for what he is doing. And, given that he is only adding the constants because they don't exist in very old versions of Perl, it is likely that he is trying to support a version of Perl prior to 5.004 (which introduced the constant pragma). -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/