Perl special variables
Input and output special variables
$_- Default input and pattern search variables
@_- Array of subroutine parameters
$.- Current line number
$/- Enter record separator
$\- Output record delimiter
$|- Automatic refresh
$"- List interpolation separator
$,- Output field separator
Pattern matching special variables
$1, $2, $3, ... - capturing group
$&- matching string
`$`` - the string before the match
$'- The matched string
$+- the last capturing group
$^N- Recently completed capture groups
Process special variables
$$- Current process ID
$?- The exit status of the last child process
$0- Program name
$^O- Operating system name
$^T- Script start time
$^X- Perl interpreter path
File handle special variables
ARGV- Command line parameters
@ARGV- Array of command line parameters
STDIN, STDOUT, STDERR
Format special variables
$#- the last index of the array
$%- Current page number
$=- Number of lines per page
$-- Current number of rows
$~- Current format name
Regular expression special variables
$^R- The final successful regular expression code execution result
Other important special variables
$!- System error messages
$@-eval error message
$^E- Extended error messages
$^I- Edit backup extensions in place
$^F- Maximum system file descriptor size
$^H- syntax hash (used internally)
$^M- Emergency memory pool
$^P- debugger flags
$^S- Current interpreter status
$^V- Perl version
Practical example
Example 1: Line numbers and file handling
Example 2: Regular expression extraction
Example 3: Command line tools
Example 4: Progress display
Summary
This chapter learned about Perl’s special variables:
- ✅ Input and output special variables
- ✅ Pattern matching special variables
- ✅ Process special variables
- ✅ File handle special variables
- ✅ Format special variables
- ✅ Other important special variables
Next, we'll learn about Perl Regular Expressions.