Perl Reference Guide
- Command Line Options
- -0[octal]
- specify record seperator (\0, if no argument)
- -a
- autosplit mode with -n or -p
- -c
- check syntax only (runs BEGIN and END blocks)
- -d[:debugger]
- run scripts under debugger
- -D[number/list]
- set debuging flags (argument is a bit mask or flags)
- -e command
- onle line of script, multiple -e options are allowed [filename] can be ommited when -e is used
- -F regexp
- regular expression for autosplit (-a)
- -i
- edit <> files in place (make backup if extension supplied)
- -l[octal]
- enable line ending processing, specifies line terminator
- -n
- assume 'while(<>){. . .}' loop around your script
- -p
- assum loop line -n but print line also like sed
- -P
- run script through C preprocessor before compilation
- -s
- enable some switch parsing for switches after script name
- -S
- look for the script using PATH environment variable
- -T
- turn on tainting checks
- -u
- dump core after parsing script
- -U
- allow unsafe operations
- -v
- print version number and patch level of perl
- -V[:variable]
- print perl configuration information
- -w
- turn warnings on for compilation of your script
- -x[directory]
- strip off text before #!perl line and perhaps cd to directory
- Literals
- Numeric
- 123 123.4 5E9 0xffff(hex) 0377(octal)
- String
- 'abc' - literal string, no interpolation occurs
- "abc" - interpolation occurs
- Array
- () - empty array
- (1,2,3) - three element array
- Hash
- (key1,val1,key2,val2,...)
- Variables
- $var
- A simple scalar variable
- @array
- An array variable
- $array[5]
- The 4th element of an array
- @array[3,4]
- A slice of @array
- %hash
- A hash variable
- $hash{'one'}
- The value of the hash variable with an index of one
- Operators
- ->
- ++
- --
- **
- \
- ! ~
- + -
- =~
- !~
- * / % x
- + - .
- >> <<
- name unary operators
- < > <= >=
- lt gt l ge
- == != <=>
- eq ne cmp
- &
- | ^
- ||
- .. (range operator)
- ? : (ternary operator)
- = += -= ...
- ,
- =>
- Statements
- if (expr) block [[elsif (expr) block] else block]
- The if statements
- unless(expr) block [else block]
- The unless statement
- while (expr) block
- The while loop
- until (expr) block
- The until loop
- for([expr];[expr];[expr]) block
- The for loop
- do block while (expr)
- The do-while loop
- do block until (expr)
- The do-until loop
- foreach [var] (list) block
- The foreach loop
- last [label]
- Used immediately exit a loop
- next [label]
- Used to go the next iteration of a loop
- redo [label]
- Used to restart the loop without evaluating the condition
- Regular Expressions
- .
- Matches any character except a newline unless the \s modifier is used
- ( ... )
- Groups a series of pattern elements to a signle element
- ^
- Matches the beginning of a line
- $
- Marches the end of a line
- [...]
- Sets up a class of characters to match, if [^...] it excludes these.
- |
- Gives you an alternative
- +
- Matches the preceding character one or more times
- ?
- Matches the preceding character zero or one times
- *
- Matches the preceding character zero or more times
- {n,m}
- implies the minimum n and maximum m match count. {n} means exactly n times. {n,} means at least n times.
- \w
- Matches alphanumeric characters
- \s
- Matches whitespace
- \S
- Matches non-whitespace
- \d
- Matches numeric
- \D
- Matches non-numeric
- \b
- Matches word-boundries
- \B
- Matches non-word boundries
- File Operators
- -r -w -x
- Test if file is readable/writable/executable by user
- -R -W -X
- Test if file is readable/writable/executable by real user
- -o -0
- Test if file is owned by the user/real user
- -e -z
- Test if file exist/has zero size
- -s
- Test if file exist and has a non-zero size. This returns the size.
- -f -d
- Test if file is plain/directory
- -l -S -p
- Test if file is symbolic link/socket/name pipe
- -b -c
- Test if file is a block/character special file
- -u -g -k
- File has setuid/setgid/sticky bit set
- -t
- Test if filehandle is opened to a tty
- -T -B
- Test if file is text/binary
- -M -A -C
- File modification/access/inode-change time.
- Special Variables
- $_
- The default variable
- $.
- The current input line
- $?
- The status returned by the last `...`command, pipe
- $]
- The Perl version number
- $[
- The index of the first element of an array
- $0
- The name of the file containing the Perl script being executed.
- $$
- Teh process ID of the Perl interpreter running this script
- $@
- The Perl error message from the last eval or do expr command
- $&
- The string matched by the last successful pattern match
- $`
- The string preceding what was matched by teh last succesful match
- $'
- The string followed what was matched by the last successful match.
- $ARGV
- The name of the current file when reading from < >
- @ARGV
- Contains the command line arguments for the script
- @_
- Parameter array for subroutines
- %ENV
- Contains the current environment variable
-
- Functions
- chdir
- Changes to specified directory
- chomp
- Removes characters from end of sring corresponding to the input line seperator
- chop
- Removes the last characters
- close
- Closes a filehandlde
- closedir
- Closes a directory opened by opendir()
- defined
- Returns a boolean value depending of whether the variable is defined or not.
- delete
- Use this function to delete an element from a hash given a specified key
- die
- Terminates execution of a perl script
- each
- Allows you loop through a hash, it returns the key and value
- eof
- Test to see if at the end of file
- eval
- Executes a perl expression like a program returning the value of the last statement executed
- exists
- Test if a given key exist in a hash
- exit
- Exits the program with a specified error
- glob
- Returns the list of files resulting from expanding the expression with any wildcards.
- grep(expr,list)
- Evaluates the expression or block for each of the elements supplied in the list
- index
- returns the position in the suplied string where the substring first occurs
- join
- Converts a list into a string with the specified seperator character
- keys
- Returns a list comprising the name of each that exist in a hash
- length
- Returns the length of a string
- open
- Opens a specified file with the specified filehandle
- opendir
- Opens a specified directory
- print
- prints to the specified filehandle
- push
- Appends elements to the specified list
- readdir
- Returns a list of files specified by the directory handle
- shift
- Takes the left most element from an array and returns that
- split
- Takes a string and splits it into a list based of the specified expression
- unshift
- Inserts an element into the beginning of a list
- values
- Returns the values that exist in a hash
Return To Index