While reading about the pragma overload of Perl5, I noticed the operator *{}.
I’d like to know what kind of sigil * is, if any, or what’s the meaning of * in a ref context.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
*foois a “typeglob”, or “glob” for short. A glob is a structure (as in Cstruct) with fields namedARRAY,HASH,IO, etc. These fields either contain nothing or a reference. From the perspective of Perl code, they look like very special hashes.The primary purpose of globs is to server as entries for Perl’s symbol table. The symbol table holds all symbols that belong to a package and all “truly global” variables (e.g.
STDOUT,$1, etc). Without the symbol, there would be no named subroutines,@ISAand@EXPORTwouldn’t exist, and neither would@_,$$, etc. [Obviously, globs are most definitely not legacy.]Globs are also used as wrappers around IO objects (file handles). Even
open(my $fh, ...)populates$fhwith a glob.Globs are very rarely used explicitly in Perl. The one exception is old-style file handles. For example,
FILEandSTDOUTactually means*FILEand*STDOUT(when used as file handles), which in term are used to get*FILE{IO}and*STDOUT{IO}.So why would you want to override
*{}?You would want to override
*{}if you wanted to create an object that looks like a file handle without actually being a file handle. For example, you could use this override to make IO::Socket object hash-based objects instead of glob-based objects.