Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>*foo</code> is a "typeglob", or "glob" for short. A glob is a structure (as in C <code>struct</code>) with fields named <code>ARRAY</code>, <code>HASH</code>, <code>IO</code>, etc. These fields either contain nothing or a reference. From the perspective of Perl code, they look like very special hashes.</p> <p>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. <code>STDOUT</code>, <code>$1</code>, etc). Without the symbol, there would be no named subroutines, <code>@ISA</code> and <code>@EXPORT</code> wouldn't exist, and neither would <code>@_</code>, <code>$$</code>, etc. [Obviously, globs are most definitely not legacy.]</p> <pre><code>$ perl -E' our @foo = qw( a b c ); our %foo = ( d=&gt;4, e=&gt;5 ); say @{ *foo{ARRAY} }; say %{ *foo{HASH} }; ' abc d4e5 </code></pre> <p>Globs are also used as wrappers around IO objects (file handles). Even <code>open(my $fh, ...)</code> populates <code>$fh</code> with a glob.</p> <p>Globs are very rarely used explicitly in Perl. The one exception is old-style file handles. For example, <code>FILE</code> and <code>STDOUT</code> actually means <code>*FILE</code> and <code>*STDOUT</code> (when used as file handles), which in term are used to get <code>*FILE{IO}</code> and <code>*STDOUT{IO}</code>.</p> <pre><code>$ perl -e'open(FILE, "echo foo|") or die; print readline(FILE);' foo $ perl -e'open(*FILE, "echo foo|") or die; print readline(*FILE);' foo $ perl -e'open(*FILE{IO}, "echo foo|") or die; print readline(*FILE{IO});' foo </code></pre> <p><strong>So why would you want to override <code>*{}</code></strong>?</p> <p>You would want to override <code>*{}</code> 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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload