Special Vars Quick Reference Cheat Sheet

A Programming › Perl cheat sheet in English by respi

Special Vars Quick Reference

7,172 views 2,399 downloads 8 Sep 2014 History
3.7 avg · 0 ratings

Standard

$_
The default or implicit variable
@_
Subroutine parameters
$a $b
Sort comparison routine variables
@ARGV
The comman­d-line args

ID's and Process Inform­ation

$$
Process ID
$<
Real user id of process
$>
Effective user id of process
$(
Real group id of process
$)
Effective group id of process
$0
Program name
$^O
Operating System name

Encoding

${^ENC­ODING}
The object reference to the Encode object, used to convert the source code to Unicode
${^OPEN}
Internal use: \0 separated Input / Output layer inform­ation
${^UNI­CODE}
Read-only Unicode settings
${^UTF­8CACHE}
State of the internal UTF-8 offset caching code
${^UTF­8LO­CALE}
Indicates whether UTF8 locale was detected at startup

Miscel­laneous

@F
Autosplit (-a mode) recipient
@INC
List of library paths
%INC
Keys are filenames, values are paths to modules included via use, require, or do
%ENV
Hash containing current enviro­nment variables
%SIG
Signal handlers
$[
Array and substr first element (Depre­cated!)

Status Reporting

$?
Child error. Status code of most recent system call or pipe
$!
Operating System Error. (What just went '­ban­g'?)
$^E
Extended Operating System Error (Extra error explan­ation)
$@
Eval error
${^CHI­LD_­ERR­OR_­NATIVE}
Native status returned by the last pipe close, backtick (`` ) command, successful call to wait() or waitpid(), or from the system() operator

IO and Separators

$.
Current line number (or record number) of most recent filehandle
$/
Input record separator
$|
Output autoflush. 1=auto­flush, 0=default. Applies to currently selected handle
$,
Output field separator (lists)
$\
Output record separator
$"
Output list separator. (inter­polated lists)
$;
Subscript separator. (Use a real multid­ime­nsional array instead)

Regular Expres­sions

$<d­igi­t>
Regexp parent­hetical capture holders
$&
Last successful match (degrades perfor­mance)
${^MATCH}
Similar to $& without perfor­mance penalty. Requires /p modifier
$`
Prematch for last successful match string (degrades perfor­mance)
${^PRE­MATCH}
Similar to $` without perfor­mance penalty. Requires /p modifier
$'
Postmatch for last successful match string (degrades perfor­mance)
${^POS­TMATCH}
Similar to $' without perfor­mance penalty. Requires /p modifier
$+
Last paren match
$^N
Last closed paren match (last submatch)
@+
Offsets of ends of successful submatches in scope
@-
Offsets of starts of successful submatches in scope
%+
Like @+, but for named submatches
%-
Like @-, but for named submatches
$^R
Last regexp (?{code}) result
${^RE_­DEB­UG_­FLAGS}
Current value of regexp debugging flags. See use re '­deb­ug'
${^RE_­TRI­E_M­AXBUF}
Control memory alloca­tions for RE optimi­zations for large altern­ations

Perl Status Info

$]
Old: Version and patch number of perl interp­reter. Deprecated
$^C
Current value of flag associated with -c switch
$^D
Current value of debugging flags
$^F
Maximum system file descriptor
$^I
Value of the -i (inplace edit) switch
$^M
Emergency Memory pool
$^P
Internal variable for debugging support
$^R
Last regexp (?{code}) result
$^S
Exceptions being caught. (eval)
$^T
Base time of program start
$^V
Perl version
$^W
Status of -w switch
${^WAR­NIN­G_BITS}
Current set of warning checks enabled by use warnings;
$^X
Perl executable name
${^GLO­BAL­_PHASE}
Current phase of the Perl interp­reter
$^H
Internal use only: Hook into Lexical Scoping
%^H
Intern­aluse only: Useful to implement scoped pragmas
${^TAINT}
Taint mode read-only flag
${^WIN­32_­SLO­PPY­_STAT}
If true on Windows stat() won't try to open the file

Command Line Args

ARGV
Filehandle iterates over files from command line (see also <>)
$ARGV
Name of current file when reading <>
@ARGV
List of command line args
ARGVOUT
Output filehandle for -i switch

Badges

Good Cheat Sheet Nice Cheat Sheet

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.