develooper Front page | perl.beginners | Postings from September 2009

Typeglobs, constants and sub refs

Thread Next
Matteo Riva
September 17, 2009 04:31
Typeglobs, constants and sub refs
Message ID:
After reading Uri's post about projects for beginners, I took a quick
look at File::Slurp source code, and I was stuck at the very beginning.

My knowledge of Perl is still very beginner level, but I want - time
allowing - to improve as I like the language very much.

Anyway, the code starts with this comment and few lines of code:

# Install subs for various constants that aren't set in older perls
# (< 5.005).  Fcntl on old perls uses Exporter to define subs without a
# () prototype These can't be overridden with the constant pragma or
# we get a prototype mismatch.  Hence this less than aesthetically
# appealing BEGIN block:

	unless( eval { defined SEEK_SET() } ) {
		*SEEK_SET = sub { 0 };
		*SEEK_CUR = sub { 1 };
		*SEEK_END = sub { 2 };

and more to follow wich - to my understanding - define constants which
act as flags with usual binary ANDs and ORs. Since the quoted comment
didn't really shed much light on my ignorance, I'm here to ask exactly
what that code does. Probably the main point I'm missing is the use of
typeglobs? Any pointer to a better explanation of the topic - if it's
too wide for a single email reply - would be very much welcome.

Thanks for your help

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About