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

Typeglobs, constants and sub refs

Thread Next
From:
Matteo Riva
Date:
September 17, 2009 04:31
Subject:
Typeglobs, constants and sub refs
Message ID:
f437ec30909170431r6ba521e5gf028c8d131aa9bce@mail.gmail.com
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:

BEGIN {
	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
matteo

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About