Perl reference

Reference for various things in Perl. See also Perl built-in functions.

Arithmetic
{|
 * + || add || $x+$y
 * - || subtract || $x-$y
 * * || multiply || $x*$y
 * / || divide || $x/$y
 * % || modulo (remainder) || $x%$y -&gt; remainder of x/y
 * ** || exponent || $x**$y -&gt; xy
 * ++ || incrememt || $x++ or ++$x -&gt; x is incremented by 1
 * -- || decrement || $x-- or --$x -&gt; x is decremented by 1
 * colspan=3 |
 * % || modulo (remainder) || $x%$y -&gt; remainder of x/y
 * ** || exponent || $x**$y -&gt; xy
 * ++ || incrememt || $x++ or ++$x -&gt; x is incremented by 1
 * -- || decrement || $x-- or --$x -&gt; x is decremented by 1
 * colspan=3 |
 * -- || decrement || $x-- or --$x -&gt; x is decremented by 1
 * colspan=3 |
 * colspan=3 |
 * colspan=3 |

Comparisons

 * == || is equal || $x==$y returns true iff x equals y
 * != || is different || $x!=$y returns true iff x does not equal y
 * &lt; || is less than || $x&lt;$y returns true iff x is smaller than y
 * &gt; || is more than || $x&gt;$y returns true iff x is larger than y
 * colspan=3 |
 * &lt; || is less than || $x&lt;$y returns true iff x is smaller than y
 * &gt; || is more than || $x&gt;$y returns true iff x is larger than y
 * colspan=3 |
 * colspan=3 |
 * colspan=3 |

Strings

 * . || concatenate || $x.$y combines the strings in x and y
 * eq || strings are equal || $xeq$y returns true iff the two strings are identical
 * ne || strings are different || $xne$y returns true iff the two strings are different
 * colspan=3 |
 * ne || strings are different || $xne$y returns true iff the two strings are different
 * colspan=3 |
 * colspan=3 |
 * colspan=3 |

Other

 * ?: || conditional result || $a?$b:$c returns $b if $a is true, otherwise returns $c
 * }
 * }

File Test Operators
All operators are used like this: -x $filename

Special Variables
{|
 * @ARGV || array of command-line arguments with which Perl was invoked
 * %ENV || hash of all environment variables (see http://vbz.net/cgi-bin/env for a sample listing)
 * $0 || name of Perl program file (the outermost one; may or may not include path, depending on system (in Linux, it does not))
 * $^A || current value of the accumulator used by the write function
 * $^D || current value of Perl's debugging flags
 * $^F || maximum system file descriptor (typically 2) not sure what this means
 * $^L || what characters are printed to accomplish a form feed
 * $^T || time at which the script began running, in seconds since 00:00:00 GMT January 1, 1970
 * $^W || is true if warnings have been turned on (by running Perl with the -w command option)
 * $^X || filespec of the Perl interpreter
 * $_ || The default input and pattern-searching space; default argument for many functions.
 * @_ || list of arguments passed to subroutine (usually in parentheses)
 * $) || effective group ID of the current process (UNIX/Linux)
 * $( || real group ID of the current process (UNIX/Linux)
 * $] || version number of the Perl interpreter
 * $[ || The index of the first element in an array, and of the first character in a substring.
 * $&lt; || username of user running the Perl script real user ID of the current process (UNIX/Linux) (may not be very useful for CGI because Apache always executes as the same user)
 * $&gt; || effective user ID of the current process (UNIX/Linux)
 * $/ || string to be used as input record separator; default = newline
 * $\ || string to be used as output record separator in print
 * $: || "soft-hyphen" characters, i.e. the set of characters after which a line may be broken to fill continuation fields (starting with ^) in a format. Default is space, newline, hyphen.
 * $; || The subscript separator for multi-dimensional array emulation.
 * $. || The current input line number (or record number) of the last filehandle that was read.
 * $, || output field separator for print function, i.e. the separator for printing arrays
 * $" || This is similar to "$," except that it applies to array values interpolated into a double-quoted string (or similar interpreted string)
 * $# || The output format for numbers display via print
 * $$ || The process number of the Perl running this script
 * $? || The status returned by the last child process, i.e. pipe close, backtick(``) command or system operator.
 * $! || If used in a numeric context, yields the current value of errno, with all the usual caveats. (This means that you shouldn't depend on the value of $! to be anything in particular unless you've gotten a specific error return indicating a system error.) If used in a string context, yields the corresponding sysem error string.
 * $@ || The Perl syntax error or routine error message from the last eval, do-FILE, or require command. If set, either the compilation failed, or the die function was executed within the code of the eval.
 * colspan=2 |
 * $[ || The index of the first element in an array, and of the first character in a substring.
 * $&lt; || username of user running the Perl script real user ID of the current process (UNIX/Linux) (may not be very useful for CGI because Apache always executes as the same user)
 * $&gt; || effective user ID of the current process (UNIX/Linux)
 * $/ || string to be used as input record separator; default = newline
 * $\ || string to be used as output record separator in print
 * $: || "soft-hyphen" characters, i.e. the set of characters after which a line may be broken to fill continuation fields (starting with ^) in a format. Default is space, newline, hyphen.
 * $; || The subscript separator for multi-dimensional array emulation.
 * $. || The current input line number (or record number) of the last filehandle that was read.
 * $, || output field separator for print function, i.e. the separator for printing arrays
 * $" || This is similar to "$," except that it applies to array values interpolated into a double-quoted string (or similar interpreted string)
 * $# || The output format for numbers display via print
 * $$ || The process number of the Perl running this script
 * $? || The status returned by the last child process, i.e. pipe close, backtick(``) command or system operator.
 * $! || If used in a numeric context, yields the current value of errno, with all the usual caveats. (This means that you shouldn't depend on the value of $! to be anything in particular unless you've gotten a specific error return indicating a system error.) If used in a string context, yields the corresponding sysem error string.
 * $@ || The Perl syntax error or routine error message from the last eval, do-FILE, or require command. If set, either the compilation failed, or the die function was executed within the code of the eval.
 * colspan=2 |
 * $, || output field separator for print function, i.e. the separator for printing arrays
 * $" || This is similar to "$," except that it applies to array values interpolated into a double-quoted string (or similar interpreted string)
 * $# || The output format for numbers display via print
 * $$ || The process number of the Perl running this script
 * $? || The status returned by the last child process, i.e. pipe close, backtick(``) command or system operator.
 * $! || If used in a numeric context, yields the current value of errno, with all the usual caveats. (This means that you shouldn't depend on the value of $! to be anything in particular unless you've gotten a specific error return indicating a system error.) If used in a string context, yields the corresponding sysem error string.
 * $@ || The Perl syntax error or routine error message from the last eval, do-FILE, or require command. If set, either the compilation failed, or the die function was executed within the code of the eval.
 * colspan=2 |
 * $? || The status returned by the last child process, i.e. pipe close, backtick(``) command or system operator.
 * $! || If used in a numeric context, yields the current value of errno, with all the usual caveats. (This means that you shouldn't depend on the value of $! to be anything in particular unless you've gotten a specific error return indicating a system error.) If used in a string context, yields the corresponding sysem error string.
 * $@ || The Perl syntax error or routine error message from the last eval, do-FILE, or require command. If set, either the compilation failed, or the die function was executed within the code of the eval.
 * colspan=2 |
 * $@ || The Perl syntax error or routine error message from the last eval, do-FILE, or require command. If set, either the compilation failed, or the die function was executed within the code of the eval.
 * colspan=2 |
 * colspan=2 |

Output Flags

 * $| || If set to nonzero, forces a flush after every write or print
 * $* || If set to zero, pattern-matching assumes that strings contain a single line (for optimization purposes). Default = 0
 * colspan=2 |
 * $* || If set to zero, pattern-matching assumes that strings contain a single line (for optimization purposes). Default = 0
 * colspan=2 |
 * colspan=2 |

Reporting
These refer to the currently selected filehandle; each filehandle maintains its own set of variables.
 * $% || Current page number
 * $= || Current page length
 * $- || Number of lines remaining on the page
 * $~ || Name of the current report format (default is the filenandle's name)
 * $^ || Name of the current top-of-page format (default is the filehandle's name plus "_TOP")
 * colspan=2 |
 * $~ || Name of the current report format (default is the filenandle's name)
 * $^ || Name of the current top-of-page format (default is the filehandle's name plus "_TOP")
 * colspan=2 |
 * $^ || Name of the current top-of-page format (default is the filehandle's name plus "_TOP")
 * colspan=2 |
 * colspan=2 |

Pattern Matching (regex)
These are associated with the last successful pattern match. Portions of this were shamelessly copied from here, at least until more information can be found. Other portions were copied from Discover Perl 5 by Naba Barkakati, ISBN 0-7645-3076-3
 * $ n  || in the replacement section, indicate that the n th matched section in parentheses should be used here (first matched parentheses becomes $1, second becomes $2, etc., up through $9)
 * $& || Contains the string matched by the last pattern match. Introduces CPU/memory overhead for all regex operations in the script; avoid.
 * $` || The string preceding whatever was matched by the last pattern match, not counting patterns matched in nested blocks that have been exited already. Introduces CPU/memory overhead for all regex operations in the script; avoid.
 * $' || The string following whatever was matched by the last pattern match, not counting patterns matched in nested blockes that have been exited already. Introduces CPU/memory overhead for all regex operations in the script; avoid.
 * $+ || The last bracket matched by the last search pattern. This is useful if you don't know which of a set of alternative patterns matched.
 * $* || When set to 1, string searching is done for multiple lines within the string (i.e. if the string contains newline characters); otherwise, presumably the search stops at the first newline.
 * }
 * $' || The string following whatever was matched by the last pattern match, not counting patterns matched in nested blockes that have been exited already. Introduces CPU/memory overhead for all regex operations in the script; avoid.
 * $+ || The last bracket matched by the last search pattern. This is useful if you don't know which of a set of alternative patterns matched.
 * $* || When set to 1, string searching is done for multiple lines within the string (i.e. if the string contains newline characters); otherwise, presumably the search stops at the first newline.
 * }
 * $* || When set to 1, string searching is done for multiple lines within the string (i.e. if the string contains newline characters); otherwise, presumably the search stops at the first newline.
 * }
 * }
 * }