Home > Mobile >  What does * before a Perl variable name mean?
What does * before a Perl variable name mean?

Time:09-29

What does the Perl statement below mean?

*INPUT_DATA                    =\ 0;

I checked some Perl documentation sites also like https://perldoc.perl.org/variables, but I couldn't find a similar example.

CodePudding user response:

In short, * denotes a "typeglob", which is an internal type holding the values of all global variables of the given name. It's still sometimes used for filehandles in older code or to create aliases.

See perldata for the explanation of typeglobs, and also see the links recommended at the end of the page, i.e. perlvar, perlref, perlsub, and perlmod.

CodePudding user response:

It create a read-only variable named $INPUT_DATA with value 0. In other words,

*INPUT_DATA = \0;

is basically equivalent to

use Readonly;
 
Readonly::Scalar $INPUT_DATA => 0;

It is done through manipulation of the symbol table.

* denotes a glob aka typeglob which is basically a C struct that contain one of each type of variables (scalar, array, code, glob, file handle, directory handle, format, etc). The symbol table is a tree of globs.

  •  Tags:  
  • perl
  • Related