On Thu, Sep 17, 2009 at 13:34, Matteo Riva <mura...@gmail.com> wrote:
> On Thu, Sep 17, 2009 at 5:56 PM, Uri Guttman <u...@stemsystems.com> wrote:
>
>> hopefully that explains it.
>
> Unfortunately, not really :)
>
> I *know* about the symbol table and typeglobs, but I yet have to
> *understand* how it all works, and how to use it.
>
> My first question here - before everything else - is: why subs to just
> return an integer? Why not directly use the number itself?
snip

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.

[1] : http://p.einarsen.no/?p=109
[2] : http://www.enlightenedperl.org/ironman.html

-- 
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/


Reply via email to