Identifiers

Learn the basics of identifiers/naming conventions in the Perl language.

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 UTF-8UTF-8 is a commonly used variable-length encoding of unicode characters. It uses only one byte to represent ASCII characters. word characters in identifiers.

These are valid Perl identifiers:

Press + to interact
my $name;
my @_private_names;
my %Names_to_Addresses;
sub anAwkwardName3;

This works with utf8 pragma enabled:

Press + to interact
use utf8;
package Ingy::Döt::Net;

These are invalid Perl identifiers:

Press + to interact
my $invalid name; # space is invalid
my @3; # cannot start with number my
%~flags; # symbols invalid in name
package a-lisp-style-name; # use underscore instead

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. ...