For example, this: print "The array is: equivalent to this: print "The array is: ". When an array or an array slice is interpolated into a double-quoted string or a similar context such as /./, its elements are separated by this value. Inside a subroutine, is the default array for the array operators pop and shift. # a subroutine the array contains the parameters passed to that subroutine. Mnemonic: underline is understood in certain operations. This experimental feature was removed and is now a fatal error, but you may encounter it in older code. Making $_ refer to the global $_ in the same scope was then possible with our $_. However, between perl v5.10.0 and v5.24.0, it could be used lexically by writing my $_. Outside a while test, this will not happen.
The default place to put the next value or input record when a, readline, readdir or each operation's result is tested by itself as the sole criterion of a while test. The implicit iterator variable in the grep() and map() functions. The default iterator variable in a foreach loop if no other variable is supplied. The pattern matching operations m//, s/// and tr/// (aka y///) when used without an =~ operator. The following functions use $_ as a default argument:Ībs, alarm, chomp, chop, chr, chroot, cos, defined, eval, evalbytes, exp, fc, glob, hex, int, lc, lcfirst, length, log, lstat, mkdir, oct, ord, pos, print, printf, quotemeta, readlink, readpipe, ref, require, reverse (in scalar context only), rmdir, say, sin, split (for its second argument), sqrt, stat, study, uc, ucfirst, unlink, unpack.Īll file tests ( -f, -d) except for -t, which defaults to STDIN. Here are the places where Perl will assume $_ even if you don't use it:
These must all be written in the form $ # equivalent only in while! Since Perl v5.6.0, Perl variable names may also be alphanumeric strings preceded by a caret. These names are all reserved for special uses by Perl for example, the all-digits names are used to hold data captured by backreferences after a regular expression match. Perl variable names may also be a sequence of digits, a single punctuation character, or the two-character sequence: ^ (caret or CIRCUMFLEX ACCENT) followed by any one of the characters. A Unicode letter that is not ASCII is not considered to be a letter unless "use utf8" is in effect, and somewhat more complicated rules apply see "Identifier parsing" in perldata for details. In this case, the part before the last :: or ' is taken to be a package qualifier see perlmod. Usually, they must begin with a letter or underscore, in which case they can be arbitrarily long (up to an internal limit of 251 characters) and may contain letters, digits, underscores, or the special sequence :: or '.
Variable names in Perl can have several formats. Perlvar - Perl predefined variables #DESCRIPTION # The Syntax of Variable Names Variables related to the interpreter state.Variables related to regular expressions.