What do Perl identifiers starting with an asterisk * mean?

I have this routine that has identifiers defined as

*VALID_NAME_REG_EX = \"[ a-zA-Z0-9_#.:@=-]+"; *MACRO_VALID_NAME = \"MACRO_VALID_NAME"; 

I looked at the file further. They are referred to as $MACRO_VALID_NAME .

I assume that it replaces the value with the right side of the string, but I'm not sure about it and want to get confirmation.

+5
source share
2 answers
 *VALID_NAME_REG_EX = \"[ a-zA-Z0-9_#.:@=-]+"; 

The effect is to assign $VALID_NAME_REG_EX as the Perl string literal identifier "[ a-zA-Z0-9_#.:@=-]+"

It is different from the word

 $VALID_NAME_REG_EX = "[ a-zA-Z0-9_#.:@=-]+" 

which copies the string to the space assigned to $VALID_NAME_REG_EX so that you can change it later

Perl literals must be read-only in order to make sense, so the result of the assignment is to make $VALID_NAME_REG_EX -only variable, otherwise known as a constant. If you try to assign it, you will receive a message similar to

Modify a read-only value

+7
source

* in perl stands for typeglob

Perl uses an internal type called typeglob to store the entire character table entry. The typeglob type prefix is ​​* because it represents all types. This used to be the preferred way to pass arrays and hashes by reference to a function, but now that we have real links, this is rarely required.

The main use of globs types in modern Perl is to create symbol table aliases. This assignment:

*this = *that;

makes $this alias for $that , @this alias for @that that, %this alias for %that , &this alias for &that , etc. It’s much safer to use the link.

+3
source

Source: https://habr.com/ru/post/1241807/


All Articles