Appendix A. Perl’s Special Variables
In this appendix, I summarize Perl’s most commonly used special (predefined) variables, such as $_
, $.
, $/
, $\
, $1
, $2
, $3
(and so on), $
,, @F
, and @ARGV
, among others.
A.1 Variable $_
The $_
variable, called the default variable, is the most commonly used variable in Perl. Often this variable is pronounced “it” (when not pronounced “dollar-underscore”); as you read on, you’ll understand why.
When using the -n
and -p
command-line arguments, it’s (see?) where the input is stored. Also, many operators and functions act on it implicitly. Here’s an example:
perl -le '$_ = "foo"; print'
Here, I place the string "foo"
in the $_
variable and then call print
. When given no arguments, print
prints the contents of the $_ ...
Get Perl One-Liners now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.