Difference between revisions of "Perl reference"
Jump to navigation
Jump to search
(→File Test Operators: special variables) |
m (→Special Variables: some more vars) |
||
Line 95: | Line 95: | ||
| '''$^X''' || [[filespec]] of the Perl interpreter | | '''$^X''' || [[filespec]] of the Perl interpreter | ||
|- | |- | ||
− | | '''$/''' || not sure what this does | + | | '''$/''' || string to be used as input record separator |
+ | |- | ||
+ | | '''$\''' || string to be used as output record separator | ||
+ | |- | ||
+ | | '''$=''' || not sure what this does | ||
+ | |- | ||
+ | | '''$~''' || not sure what this does | ||
+ | |- | ||
+ | | '''$.''' || current record number in input | ||
|- | |- | ||
| '''$<u>n</u>''' || used within [[Perl regex|regular expressions]] to indicate that the matched section in parentheses should be used here (first matched parentheses becomes $1, second becomes $2, etc.) | | '''$<u>n</u>''' || used within [[Perl regex|regular expressions]] to indicate that the matched section in parentheses should be used here (first matched parentheses becomes $1, second becomes $2, etc.) | ||
|} | |} |
Revision as of 22:27, 12 March 2006
Reference for various things in Perl. See also Perl built-in functions.
Escape Sequences
\a | bell (ctrl-G, 007 decimal) |
\b | backspace (ctrl-H, 008 decimal) |
\cn | ctrl-n |
\e | ESC (027 decimal, 033 octal) |
\f | FF |
\l | converts next letter to lowercase |
\n | newline - system-dependent (CRLF on DOS/Win) |
\r | CR (013 decimal) |
\t | TAB (ctrl-I, 009 decimal) |
\u | converts next letter to uppercase |
\L | converts all characters to lowercase, from here to next \E |
\U | converts all characters to uppercase, from here to next \E |
\E | ends case conversion started by \L or \U |
\' | prints a literal single-quote |
\" | prints a literal double-quote |
\$ | prints a literal dollar sign |
\\ | prints a literal backslash (not doubled) |
\0nnn | prints the ASCII character numbered nnn in octal |
\xnn | prints the ASCII character numbered nn in hexadecimal |
File Test Operators
All operators are used like this:
-x $filename
-r | Is the file readable? |
-w | Is the file writable? |
-x | Is the file executable? |
-e | Does the file exist? |
-z | Is the file empty? (i.e. zero bytes) |
-s | File length in bytes |
-f | Is the file an ordinary file? |
-d | Is the file a directory? |
-l | Is the file a symbolic link? (UNIX/Linux only) |
-p | Is file a named pipe? |
-S | Is the file a socket? |
-T | Is the file a text file? |
-B | Is the file a binary file? (!-T) |
-M | Number of days since file was last modified |
-A | Number of days since file was last accessed |
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) |
$_ | default argument for many functions |
@_ | list of arguments passed to subroutine (usually in parentheses) |
$0 | name of Perl program file (the outermost one, and just the name without any path) |
$] | version number of the Perl interpreter |
$< | username of user running the Perl script (may not be very useful for CGI because Apache always executes as the same user) |
$^X | filespec of the Perl interpreter |
$/ | string to be used as input record separator |
$\ | string to be used as output record separator |
$= | not sure what this does |
$~ | not sure what this does |
$. | current record number in input |
$n | used within regular expressions to indicate that the matched section in parentheses should be used here (first matched parentheses becomes $1, second becomes $2, etc.) |