>>>>> "MR" == Matteo Riva <mura...@gmail.com> writes:

  MR> On Thu, Sep 17, 2009 at 5:56 PM, Uri Guttman <u...@stemsystems.com> wrote:
  >> hopefully that explains it.

  MR> Unfortunately, not really :)

so ask a more detailed question!

  MR> I *know* about the symbol table and typeglobs, but I yet have to
  MR> *understand* how it all works, and how to use it.

you don't need to use it in general. munging the symbol table isn't a
newbie thing. by far the most common use is in exporting symbol from
a module and that is handled by the exporter module so you never see any
globs. 

  MR> My first question here - before everything else - is: why subs to just
  MR> return an integer? Why not directly use the number itself?

symbolic constants are named vs a raw number. this is common in most
langs, to not hardwire numbers because if the number changes, you only
change it in one place and not everywhere. also it makes for more
readable code. this is an ancient design idea but perl implements it
with constant subs (and that requires a prototype with no args to allow
the compiler to optimize it). note that perl will do compile time
conversion of constant subs to the actual number so there is no slowdown
in using them.

as for file::slurp, note that i need the symbols because in some cases
their values vary from platform to platform. imagine having to check
which platform's numbers to use in each case! here i do that one time at
compile time and it works. as i said, i needed to do that hack since
older perls didn't define those constants and i needed symbols for the
above reasons.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

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