Sei sulla pagina 1di 3

PERL Cheat Sheet

PERL Practical Extraction and Reporting Language or the Pathologically Eclectic Rubbish Lister Special Symbols $@%within within ;{} /patterns &variables <>$! @_ subroutines $ $$ $#arrayName Indicates a variable Indicates a standard array(a list) Indicates an associative array(a hash table) Single quote tells PERL not to interpret anything Double quote tells PERL it is Ok to interpret what is Used to end a statement Curly brackets Used to contain a block of code Used in RegEx pattern matching or replacement Used when calling a subroutine if you want to pass in Deathstar Used to snarf in all of the data from a file handle The last error reported Used to pass variables and other stuff into List separator Process ID of the currently running process Index of the last element of an array/list

Useful Reserved Keywords (WARNING: By no means all of them) print Print to STDOUT or a file handle print This goes to STDOUT; print aFileHandle This goes to a file handle; Indicated the following block of code is a subroutine Starts a for loop for(i = 0; i < aVariable; i++) { Do something; }

sub for -

foreach -

Used to iterate over all members of an array foreach $element (@someArray) { Do something to $element; }

while -

Starts a while loop while(conditional) { Do Something; } Use pragma Used to import routines from a module Splits up a string on delimiters Take the last character off but only if it is a newline

use split chomp -

chop Take the last character off regardless of what it is(parent of chomp) exit you put in die Exit the program immediately with a message Exit the program immediately exit exit <a number> -exits with an exit code of the number

goto Goes to a particular label in the program, generally considered sloppy keys my next push pop return Find the current keys of an associative array Makes a variable local to a subroutine , used to avoid name space collisions Used in flow control to skip to the next entry if you dont want to process it Adds an new entry to an array/list Retrieves and removes an entry from an array/list Returns a variable or something from a subroutine

shift -

Shifts the first value off of an array and returns it. The same as pop, but usually used for retrieving variables and other things passed into a subroutine in the special variable @_ Sleep for a specified number of seconds sleep 1; Sleep for 1 second Array of command line arguments The author of this document does not always follow the conventional wisdom of programming PERL

sleep ARGV -

Caveat Emptor

Potrebbero piacerti anche