Identifiers
Explore Perl identifiers and variables to understand how names are formed and used in Perl programs. Learn about the role of sigils, variant sigils, context in variable usage, and the significance of namespaces in organizing code logically and efficiently.
We'll cover the following...
Names
Names (or identifiers) are everywhere in Perl programs. They exist primarily for our benefit as programmers; we choose them for variables, functions, packages, classes, and even filehandles. All valid Perl names begin with a letter or an underscore and may optionally include any combination of letters, numbers, and underscores. When the utf8 pragma is in effect, we may use any
These are valid Perl identifiers:
This works with utf8 pragma enabled:
These are invalid Perl identifiers:
Note: Names exist primarily for our benefit as a programmer.
These rules apply only to literal names that appear in our source code, such as sub fetch_pie or my $waffleiron.
Only Perl’s parser enforces the rules about identifier names. We may also refer to entities with names generated at runtime or provided as ...