* comment * This reference was adapted from the web page at: http://perldoc.perl.org/index-functions.html file made by Emmanuel Florac * version * 1.1 * language * Perl perl Quick reference cheat sheet (man perlcheat) CONTEXTS SIGILS ARRAYS HASHES void $scalar whole: @array %hash scalar @array slice: @array[0, 2] @hash{'a', 'b'} list %hash element: $array[0] $hash{'a'} &sub *glob SCALAR VALUES number, string, reference, glob, undef REFERENCES \ references $$foo[1] aka $foo->[1] $@%&* dereference $$foo{bar} aka $foo->{bar} [] anon. arrayref ${$$foo[1]}[2] aka $foo->[1]->[2] {} anon. hashref ${$$foo[1]}[2] aka $foo->[1][2] \() list of refs NUMBERS vs STRINGS LINKS OPERATOR PRECEDENCE = = perl.plover.com -> + . search.cpan.org ++ -- == != eq ne cpan.org ** < > <= >= lt gt le ge pm.org ! ~ \ u+ u- <=> cmp tpj.com =~ !~ perldoc.com * / % x SYNTAX + - . for (LIST) { }, for (a;b;c) { } << >> while ( ) { }, until ( ) { } named uops if ( ) { } elsif ( ) { } else { } < > <= >= lt gt le ge unless ( ) { } elsif ( ) { } else { } == != <=> eq ne cmp for equals foreach (ALWAYS) & | ^ REGEX METACHARS REGEX MODIFIERS && ^ string begin /i case insens. || $ str. end (before \n) /m line based ^$ .. ... + one or more /s . includes \n ?: * zero or more /x ign. wh.space = += -= *= etc. ? zero or one /g global , => {3,7} repeat in range list ops () capture REGEX CHARCLASSES not (?:) no capture . == [^\n] and [] character class \s == [\x20\f\t\r\n] or xor | alternation \w == [A-Za-z0-9_] \b word boundary \d == [0-9] \z string end \S, \W and \D negate DOs AND DON'Ts DO DON'T LINKS use strict; "$foo" perl.com use warnings; $$variable_name perlmonks.org my $var; `$userinput` use.perl.org open() or die $!; /$userinput/ perl.apache.org use Modules; parrotcode.org perldoc.perl.org FUNCTION RETURN LISTS stat localtime caller SPECIAL VARIABLES 0 dev 0 second 0 package $_ default variable 1 ino 1 minute 1 filename $0 program name 2 mode 2 hour 2 line $/ input separator 3 nlink 3 day 3 subroutine $\ output separator 4 uid 4 month-1 4 hasargs $| autoflush 5 gid 5 year-1900 5 wantarray $! sys/libcall error 6 rdev 6 weekday 6 evaltext $@ eval error 7 size 7 yearday 7 is_require $$ process ID 8 atime 8 is_dst 8 hints $. line number 9 mtime 9 bitmask @ARGV command line args 10 ctime just use @INC include paths 11 blksz POSIX:: 3..9 only @_ subroutine args 12 blcks strftime! with EXPR %ENV environment * alias * perl quoting / " perl quoting Quote and Quote-like Operators . '' or q{} - literal, no interplation or \ processing "" or qq{} - literal, with interplation `` or qx{} - command, with interplation* // or m{} - pattern match, with interplation* qw{} - word list, with interplation* qr{} - pattern, with interplation* s/// or s{}{} - substitution, with interplation* tr/// or tr{}{} - transliteration, no interplation but uses \ processing where {} can be replaced with [], {} or <> to enclose text, or with non-bracketing punctuation marks. * No interpolation occurs if '' used in place of {} with named form. Use of # as delimiter only works if no spaces between name and #, eg good: q#hello# (literal 'foo') bad: q #hello# (q operator followed by comment) cf \ for Backslash Substitutions, // for Patterns * alias * perl backslash substitutions \ perl backslash substitutions Backslash Substitutions In interpolating quoted values and transliterations: \\ - backslash \t \n \r \f \b \a - tab, newline, return, formfeed, backspace, alarm (bell) \e - escape \0oo \xXX \x{XXXX} - octal, hex, wide-char hex \cC - control character C \N{name} - named Unicode character In interpolating quoted values but *not* in transliterations: \l - lowercase next character \u - uppercase next character \L - lowercase until \E \U - uppercase until \E \Q - quote non-word characters until \E \E - terminator for \L, \U, \Q Pattern escapes \w \W: Match a "word", non-"word" character (alphanumeric plus "_") \s \S: Match a whitespace, non-whitespace character \d \D: Match a digit, non-digit character \pP \PP: Match P, non-P for named property P; use \p{Prop} for longer names \X: Match eXtended Unicode combining character sequence, same as (?:\PM\pM*) \C: Match a single C char (octet) even under Unicode NOTE: breaks up characters into their UTF-8 bytes, which may break valid UTF-8 sequences; unsupported in lookbehind. Pattern assertions \b \B: Match a word boundary, non-(word boundary) \A: Match only at beginning of string \Z: Match only at end of string, or before newline at the end \z: Match only at end of string \G: Match only at pos() (e.g. at the end-of-match position of prior m//g) \: match previous group text if no leading zero; avoid in RHS of s/// Anything else \r: the literal character r eg \. matches literal '.' * alias * perl patterns / // /// ?? {} perl patterns Patterns . Options for m//: cgimosx list context without g returns ($1, $2, $3...) [ (1) if no parens], fails with empty list context with g returns ($1, $2, $3...) or all matches if no parens scalar context with g moves through the string until failure, which resets search unless c also present; pos() returns position at end of last match. Options for qr//: imosx Options for s///: egimosx c: Do not reset search position on a failed m// match when g also in effect. e: Evaluate the right side of s/// as an expression. g: Match globally, i.e., find all occurrences. i: Do case-insensitive pattern matching. m: Treat string as multiple lines (^, $ match anywhere a \n found). o: Compile pattern only once (optimize). s: Treat string as single line (. matches \n). x: Use extended regular expressions (allows whitespace in pattern). Regular expression sequences ^ $ - match start, end of line (or just whole string if //s, but not //ms) . - match any character (incl \n if //s) () - group for extraction [] - character class: named classes are alpha alnum ascii blank cntrl digit graph lower print punct space upper word xdigit; cf [ ] | - alternation Quantifiers - if followed by ?: non-greedy x* - match x 0 or more; x+ - match x 1 or more; x? - match x 0 or 1 time x{n, m} - match x from n to m times; x{n} = x{n,n}, x{n,} = x{n}x* Pattern escapes: cf \ Extended pattern parenthetical expressions (?#comment) - no effect on pattern (singe # sufficient if x option applied) (?imsx-imsx) - turn on or off the option at this point, eg (?i-s) (?:pattern) - group without capturing ("clustering") (?imsx-imsx:pattern) - apply option changes over pattern (?=pattern) (?!pattern) - positive, negative lookahead assertion (?<=pattern) (?pattern) - match without backtracking eg ^(?>a*)ab cannot match 'aaab' since (?>a*) consumes all 'a's (?(condition)yes-pattern|no-pattern) (?(condition)yes-pattern) - conditional match: condition is either an integer designating a previous group match, or a lookahead/lookbehind evaluate yero-width assertion . Options for tr///, y///: cds c: Complement the SEARCHLIST. d: Delete found but unreplaced characters. s: Squash duplicate replaced characters. * alias * perl pattern character classes [ ] [] perl pattern character classes Pattern character classes [chars] - any one of the mentioned characters [a-z] - any one of the characters in the range a to z [-az] [az-] [a\-z] - put '-' on the edge or escape it to include it in the set [^a-z] - any one of the characters not in the range a to z (if ^ at start) [$x] - use the value of scalar $x to define the character class Named classes Names are: alpha, alnum, ascii, blank (same as [ \t]), cntrl, digit (\d), graph, lower, print, punct, space (like \s), upper, word (\w), xdigit [:name:] - class defined by name, can also use \p{IsName} (eg \p{IsGraph}) [:^name:] - class of characters not in [:name:] [cha[:name:]rs] - any one of the mentioned characters or one from class name eg the class \w is the same as [_[:alnum:]] Equivalence classes [.cc.] and [=cc=] cause errors. * comment * //////////////////////////////////////////////////////////////////////////////// perl variables * alias * perl scalar variables $ * alias * perl list/array variables @ * alias * perl hash variables % perl scalar variables Perl Scalar Variables: $ cf @ # -- indicates deprecated name or discouraged use . $_ $ARG - default value/argument $ARGV - current file read using <> (from file handle ARGV) --$[ - index of first element in an array $] - perl version + patchlevel/1000 Pattern match: $1, $2, $3, ... - text paren groups captured from pattern $+ $LAST_PAREN_MATCH - text of final paren group captured from pattern $& $MATCH - text matched by whole pattern $` $' $PREMATCH $POSTMATCH - text before/after matched pattern $^N - previous (Nth) paren-ed group within the pattern --$* - if non-zero, ^ and $ patterns match line-end, otherwise just string ends I/O $. $NR $INPUT_LINE_NUMBER - current line number of last accessed handle $/ $RS $INPUT_RECORD_SEPARATOR - "" for break at blank lines, undef for "slurp" $| $OUTPUT_AUTOFLUSH - 0 for buffered I/O, non-zero for unbuffered $, $OFS $OUTPUT_FIELD_SEPARATOR - for print command, default undef $\ $ORS $OUTPUT_RECORD_SEPARATOR - for print command, default undef $" $LIST_SEPARATOR - field separator for string output, default " " $; $SUBSEP $SUBSCRIPT_SEPARATOR - for multi-dim "array" using hashes , default "\034" Formatting --$# - printed number format, default "%.?g" where ? is the DBL_DIG value eg 17 $% $FORMAT_PAGE_NUMBER - current page number $= $FORMAT_LINES_PER_PAGE - of current output channel, default 60 $- $FORMAT_LINES_LEFT - remaining on current output page, used with formats $~ $FORMAT_NAME - of current format, default is file handle name $^ $FORMAT_TOP_NAME - of current top-of-page format, default is file handle name $: $FORMAT_LINE_BREAK_CHARACTERS - where line breaks can be added, default "\n-" $^L $FORMAT_FORMFEED - pagebreak character to output, default "\f" $^A $ACCUMULATOR - used by formline(), write() as formatted output accumulator Process $? $CHILD_ERROR - exit status/signal of ended subprocess (pipe, system, wait etc) $! $ERRNO $OS_ERROR - library failure status, "$!" gives the strerror value $^E $EXTENDED_OS_ERROR - more precise error code for VMS, Windows etc $@ $EVAL_ERROR - error in eval() as a string, or empty $$ $PID $PROCESS_ID - of current perl process $< $UID $REAL_USER_ID, $> $EUID $EFFECTIVE_USER_ID - of current perl process $( $GID $REAL_GROUP_ID, $) $EGID $EFFECTIVE_GROUP_ID - of current perl process $0 $PROGRAM_NAME - of current perl process perl list/array variables Perl List/Array Variables: @ cf $ % . @_ - parameter list passed to a subroutine @ARGV - list of command line arguments Pattern match: @+ @LAST_MATCH_END - positions in pattern operand of all paren group ends @- @LAST_MATCH_START - positions in pattern operand of all paren group starts perl hash variables Perl Hash Variables: % cf $ @ . Process %! - current error matched against mnemonic: $!{ENOENT} is true iff $! == ENOENT %ENV - environment variable values indexed by name %INC - do/require/use file paths indexed by do/require/use argument value %SIG - signal handler indexed by name, eg $SIG{'INT'} = \&subr; ARGV ARGV The special filehandle that iterates over command-line filenames in @ARGV. Usually written as the null filehandle in the angle operator <>. Note that currently ARGV only has its magical effect within the <> operator; elsewhere it is just a plain filehandle corresponding to the last file opened by <>. In particular, passing \*ARGV as a parameter to a function that expects a filehandle may not cause your function to automatically read the contents of all the files in @ARGV. $ARGV $ARGV Contains the name of the current file when reading from <>. @ARGV @ARGV The array @ARGV contains the command-line arguments intended for the script. $#ARGV is generally the number of arguments minus one, because $ARGV[0] is the first argument, not the program's command name itself. See $0 for the command name. ARGVOUT ARGVOUT The special filehandle that points to the currently open output file when doing edit-in-place processing with -i. Useful when you have to do a lot of inserting and don't want to keep modifying $_. See perlrun for the -i switch. $_ $_ $ARG Default input and pattern-searching space * alias * $ $1 $2 $3 $4 $5 $6 $7 $8 $9 $ $1, $2, $3, ... $ contains text matched by the n-th set of capturing parentheses in the last pattern match $& $& $MATCH The text matched by the previous pattern match $` $` $PREMATCH The text preceding the matched text in the string used for the previous pattern match $' $' $POSTMATCH The text following the matched text in the string used for the previous pattern match $+ $+ $LAST_PAREN_MATCH The text matched by the last bracket of the last successful search pattern. This is useful if you don't know which one of a set of alternative patterns matched. $^N $^N The text matched by the used group most-recently closed (i.e. the group with the rightmost closing parenthesis) of the last successful search pattern . eg to capture a group (...) directly in a pattern to $var, use: (?:(...)(?{ $var = $^N })) here $^N refers to preceding (...) group. @+ @+ @LAST_MATCH_END This array holds the offsets of the ends of the last successful submatches in the currently active dynamic scope. $+[0] is the offset into the string of the end of the entire match. This is the same value as what the pos function returns when called on the variable that was matched against. The nth element of this array holds the offset of the nth submatch, so $+[1] is the offset past where $1 ends, $+[2] the offset past where $2 ends, and so on. You can use $#+ to determine how many subgroups were in the last successful match. See the examples given for the @- variable. @- @- @LAST_MATCH_START This array holds the offsets of the beginnings of the last successful submatches in the currently active dynamic scope. $-[0] is the offset into the string of the beginning of the entire match. The nth element of this array holds the offset of the nth submatch, so $-[1] is the offset where $1 begins, $-[2] the offset where $2 begins, and so on. * comment * //////////////////////////////////////////////////////////////////////////////// perl functions abs # abs VALUE # abs Returns the absolute value of its argument. If VALUE is omitted, uses $_. accept # accept NEWSOCKET,GENERICSOCKET Accepts an incoming socket connect, just as the accept(2) system call does. Returns the packed address if it succeeded, false otherwise. On systems that support a close-on-exec flag on files, the flag will be set for the newly opened file descriptor, as determined by the value of $^F. alarm # alarm SECONDS schedule a SIGALRM. atan2 # atan2 Y,X arctangent of Y/X in the range -PI to PI. bind # bind SOCKET,NAME binds an address to a socket. binmode # binmode FILEHANDLE, LAYER # binmode FILEHANDLE prepare binary files for I/O. bless # bless REF,CLASSNAME # bless REF create an object. caller # caller EXPR returns context of the current subroutine call. chdir # chdir EXPR change the current working directory to EXPR or $ENV{HOME} if EXPR ommited. chmod # chmod LIST changes the permissions on a list of files. The first element of the list must be the numerical mode (usually octal). chomp # chomp VARIABLE # chomp( LIST ) # chomp remove a trailing record separator from a string or list of strings. chop # chop VARIABLE # chop( LIST ) # chop remove the last character from a string or a list of strings and returns the character chopped. If variable is a hash, chops the values, not the keys. chown # chown ( UID GID LIST ) change the owership on a list of files to UID and GID. -1 as a UID/GID leaves the value unchanged. returns the number of changed files. chr # chr NUMBER # chr get character this number represents in the character set. chroot # chroot DIRECTORY # chroot make directory new root for path lookups (you must be Root for that). close # close FILEHANDLE # close close file (or pipe or socket) handle. closedir # closedir DIRHANDLE close directory handle opened by opendir. connect # connect SOCKET,NAME connect to a remote socket. NAME should be a packed address of the appropriate type for the socket. continue # continue BLOCK optional trailing block in a while or foreach loop. Always executed. cos # cos EXPR # cos Returns the cosine of EXPR (expressed in radians). crypt # crypt PLAINTEXT,SALT one-way passwd-style encryption. When checking an encrypted string, use it as the salt. dbmclose # dbmclose HASH [This function has been largely superseded by the untie function.] Breaks the binding between a DBM file and a hash. dbmopen # dbmopen HASH,DBNAME,MASK [This function has been largely superseded by the tie function.] create binding on a tied dbm file (without the .dir or .pag extension). If the database doesn't exist, it's created with MASK access rights. defined # defined EXPR # defined test whether a value, variable, or function is defined. Use of defined on hashes and arrays is deprecated. delete # delete EXPR Given an expression that specifies a hash element, array element, hash slice, or array slice, deletes the specified element(s) from the hash or array. die # die LIST raise an exception or bail out, printing LIST to STDERR. do # do BLOCK Returns the value of the last command in the sequence of commands indicated by BLOCK. # do SUBROUTINE(LIST) A deprecated form of subroutine call. See perlsub. # do EXPR Uses the value of EXPR as a filename and executes the contents of the file as a Perl script. dump # dump LABEL # dump create an immediate core dump. each # each HASH retrieve the next key/value pair from a hash. endgrent be done using group file. endhostent be done using hosts file. endnetent be done using networks file. endprotoent be done using protocols file. endpwent be done using passwd file. endservent be done using services file. eof # eof FILEHANDLE # eof () # eof test a filehandle for its end, or if filehandle isn't open. eval # eval EXPR Run EXPR as a little perl program and returns its value. # eval BLOCK Execute BLOCK within the same perl program and trap exceptions. exec # exec LIST # exec PROGRAM LIST execute a program (with optional LIST parameters) and never returns. exists # exists EXPR test whether a hash key is present (even if undefined). exit # exit EXPR # exit Evaluates EXPR and exits immediately the program with that value, or 0 if EXPR is omitted. # exp EXPR # exp Returns e (the natural logarithm base) to the power of EXPR. fcntl # fcntl FILEHANDLE,FUNCTION,SCALAR file control system call fileno # fileno FILEHANDLE return file descriptor from filehandle. flock # flock FILEHANDLE,OPERATION lock an entire file with an advisory lock. fork # fork create a new process just like this one. format # format declare a picture format with use by the write() function. formline # formline PICTURE,LIST internal function used for formats. getc # getc FILEHANDLE # getc get the next character from the filehandle (STDIN if omitted). getgrent get next group record. getgrgid get group record given group user ID. getgrnam get group record given group name. gethostbyaddr get host record given its address. gethostbyname get host record given name. gethostent get next hosts record. getlogin # getlogin return who logged in at this tty. getnetbyaddr get network record given its address. getnetbyname get networks record given name. getnetent get next networks record. getpeername # getpeername SOCKET Returns the packed sockaddr address of other end of the SOCKET connection. getpgrp # getpgrp PID get process group for PID. Use PID 0 to get process group for the current process. getppid # getppid get parent process ID. getpriority # getpriority WHICH,WHO get current nice value. getprotobyname get protocol record given name. getprotobynumber get protocol record numeric protocol. getprotoent get next protocols record. getpwent get next passwd record. getpwnam # getpwnam NAME get passwd record given user login name. getpwuid get passwd record given user ID. getservbyname get services record given its name. getservbyport get services record given numeric port. getservent get next services record. getsockname # getsockname SOCKET retrieve packed sockaddr address of this end of the SOCKET connection. getsockopt # getsockopt SOCKET,LEVEL,OPTNAME get socket options on a given socket with a given LEVEL. glob # glob EXPR # glob expand filenames using wildcards. gmtime # gmtime EXPR convert UNIX time into record or string using Greenwich time. goto # goto LABEL # goto EXPR # goto &NAME create spaghetti code. grep # grep BLOCK LIST # grep EXPR,LIST locate elements in a list test true against a given criterion. hex # hex EXPR # hex convert a string to a hexadecimal number. import # import patch a module's namespace into your own. index # index STR,SUBSTR,POSITION # index STR,SUBSTR find a substring within a string starting from POSITION (or start if omitted). int # int EXPR # int get the integer portion of a number. ioctl # ioctl FILEHANDLE,FUNCTION,SCALAR system-dependent device control system call. join # join EXPR,LIST join a list into a string using EXPR separator and returns this string. keys # keys HASH Returns a list consisting of all the keys of the named hash. (In scalar context, returns the number of keys.) kill # kill SIGNAL, LIST send a signal to a process or a list of processes. last # last LABEL # last exit a block prematurely. lc # lc EXPR # lc return lower-case version of a string. lcfirst # lcfirst EXPR # lcfirst return a string with just the first letter in lower case. length # length EXPR # length return the number of characters in string EXPR. link # link OLDFILE,NEWFILE Creates a new filename linked to the old filename. listen # listen SOCKET,QUEUESIZE register your socket as a server. local # local EXPR create a temporary value for a global variable (dynamic scoping). localtime # localtime EXPR convert UNIX time into record or string using local time. lock # lock THING get a thread lock on a variable, subroutine, or method. log # log EXPR # log retrieve the natural logarithm for a number. lstat # lstat EXPR # lstat stat a symbolic link. m # m/REGEXP/ match a string with a regular expression pattern. map # map BLOCK LIST # map EXPR,LIST apply a change to a list to get back a new list with the changes. mkdir # mkdir FILENAME,MASK # mkdir FILENAME create a directory with MASK permissions. msgctl # msgctl ID,CMD,ARG SysV IPC message control operations. msgget # msgget KEY,FLAGS get SysV IPC message queue. msgrcv # msgrcv ID,VAR,SIZE,TYPE,FLAGS receive a SysV IPC message from a message queue. msgsnd # msgsnd ID,MSG,FLAGS send a SysV IPC message to a message queue. my # my EXPR # my TYPE EXPR # my EXPR : ATTRS # my TYPE EXPR : ATTRS declare and assign a local variable (lexical scoping). next # next LABEL # next it starts the next iteration of the loop. no # no Module VERSION LIST # no Module VERSION # no Module LIST # no Module unimport some module symbols or semantics at compile time. oct # oct EXPR # oct convert a string to an octal number. open # open FILEHANDLE,EXPR # open FILEHANDLE,MODE,EXPR # open FILEHANDLE,MODE,EXPR,LIST # open FILEHANDLE,MODE,REFERENCE # open FILEHANDLE Opens the file, pipe or command whose filename is given by EXPR, and associates it with FILEHANDLE. opendir # opendir DIRHANDLE,EXPR open a directory for processing by readdir, telldir, seekdir, rewinddir, and closedir. ord # ord EXPR # ord Returns a character's numeric representation. our # our EXPR # our EXPR TYPE # our EXPR : ATTRS # our TYPE EXPR : ATTRS declare and assign a package variable (lexical scoping). * alias * pack, unpack pack unpack pack, unpack # pack TEMPLATE,LIST Takes a LIST of values and converts it into a string using the rules given by the TEMPLATE. . # unpack TEMPLATE,EXPR converts a binary structure into a list of values according to the TEMPLATE. . TEMPLATE a string made up of groups, each group is where count is a number or * (rest of data) or of the form [] meaning count = sizeof type. A ! before the [ means align relative to the start of the data. s (including s) are: Types: - a A - binary string data, null padded / text (ASCII) string, space padded. Z - null terminated (ASCIZ) string, null padded. - b B - bit string (little-endian, like vec() / big-endian in each byte). h H - hex string (low nybble / high nybble first). - c C - signed / unsigned char (byte) value. cf U for Unicode. i I - signed / unsigned integer (at least 32 bit) value. s S - signed / unsigned short (16 bit) value. Add ! for native short size. l L - signed / unsigned long (32 bit) value. Add ! for native long size. - n N - unsigned short (16 bit) / long (32 bit) big-endian "network" order. v V - unsigned short (16 bit) / long (32 bit) little-endian "VAX" order. - q Q - signed / unsigned (64-bit) value. May have no implementation support. j J - signed / unsigned integer value (a Perl internal integer, IV / UU). f d - single / double precision float in the native format. F D - floating point / long double value in the native native format (a Perl internal floating point value, NV). - p - pointer to a null-terminated string. P - pointer to a structure (fixed-length string). u - uuencoded string. U - Unicode character number; encodes to UTF-8 internally. w - BER compressed integer (not an ASN.1 BER, see perlpacktut for details). Its bytes represent an unsigned integer in base 128, most significant digit first, with as few digits as possible. Bit eight (the high bit) is set on each byte except the last. Values: - x - A null byte. Operations: X - Back up a byte. @ - Null fill to absolute position, counted from start of innermost ()-group. ( - Start of a ()-group, allows repeat count suffix or type-letter/ prefix, rebases absolute positions for @ / - read a length followed by data, eg unpack('C/a',"\04Gurus") == 'Guru'. % - [unpack only] %type-letter computes bitlen-width sum of elements. package # package NAMESPACE # package declare a separate global namespace. pipe # pipe READHANDLE,WRITEHANDLE open a pair of connected filehandles. pop # pop ARRAY # pop remove the last element from an array and return it pos # pos SCALAR # pos find or set the offset for the last/next m//g search print # print FILEHANDLE LIST # print LIST # print output a string or a list of strings to a filehandle (or STDOUT if omitted). printf # printf FILEHANDLE FORMAT, LIST # printf FORMAT, LIST output a formatted list to a filehandle (or STDOUT if omitted). prototype # prototype FUNCTION get the prototype (if any) of a subroutine. push # push ARRAY,LIST append one or more elements to an array. q # q/STRING/ singly quote a string cf / qq # qq/STRING/ doubly quote a string qr # qr/REGEXP/ Compile REGEXP pattern. quotemeta # quotemeta EXPR # quotemeta quote all non-word characters. qw # qw/STRING/ quote a list of words. qx # qx/STRING/ backquote quote a string. rand # rand EXPR # rand Returns a random fractional number greater than or equal to 0 and less than the value of EXPR. read # read FILEHANDLE,SCALAR,LENGTH,OFFSET # read FILEHANDLE,SCALAR,LENGTH Attempts to read LENGTH characters of data into variable SCALAR from the specified FILEHANDLE. Returns the number of characters actually read, 0 at end of file, or undef if there was an error. readdir # readdir DIRHANDLE Returns the next directory entry for a directory opened by opendir. If used in list context, returns all the rest of the entries in the directory. readline # readline EXPR fetch a record from the filehandle whose typeglob is contained in EXPR. readlink # readlink EXPR # readlink determine where a symbolic link is pointing. readpipe # readpipe EXPR execute EXPR as a system command and collect standard output. recv # recv SOCKET,SCALAR,LENGTH,FLAGS receive LENGTH characters of data into variable SCALAR from the specified SOCKET filehandle. redo # redo LABEL # redo Restarts the loop block without evaluating the conditional again. The continue block, if any, is not executed. ref # ref EXPR # ref Returns a non-empty string if EXPR is a reference, the empty string otherwise. rename # rename OLDNAME,NEWNAME change a filename. require # require VERSION Demands a version of perl specified by VERSION. # require EXPR # require load in external functions from a library at runtime. reset # reset EXPR # reset clear all variables of a given name. return # return EXPR # return Returns from a subroutine, eval, or do FILE with the value given in EXPR. reverse # reverse LIST In list context, returns a list value consisting of the elements of LIST in the opposite order. In scalar context, concatenates the elements of LIST and returns a string value with all characters in the opposite order. rewinddir # rewinddir DIRHANDLE Sets the current position to the beginning of the directory for the readdir routine on DIRHANDLE. rindex # rindex STR,SUBSTR,POSITION # rindex STR,SUBSTR right-to-left substring search, starting from end or POSITION. rmdir # rmdir FILENAME # rmdir remove a directory. s # s/STRING/REGEXP/OPTIONS substitute STRING with REGEXP. scalar # scalar EXPR force a scalar context. seek # seek FILEHANDLE,POSITION,WHENCE reposition file pointer for random-access I/O. WHENCE specifies if the new position is from start (0), current position (1) or end of file (2). seekdir # seekdir DIRHANDLE,POS reposition directory pointer. POS must be a value returned by telldir. select # select FILEHANDLE # select Returns the currently selected filehandle. Sets the current default filehandle for output, if FILEHANDLE is supplied. semctl # semctl ID,SEMNUM,CMD,ARG SysV semaphore control operations. semget # semget KEY,NSEMS,FLAGS get set of SysV semaphores. semop # semop KEY,OPSTRING SysV semaphore operations. send # send SOCKET,MSG,FLAGS,TO # send SOCKET,MSG,FLAGS send a message over a socket. setgrent prepare group file for use. sethostent prepare hosts file for use. setnetent prepare networks file for use. setpgrp # setpgrp PID,PGRP set the process group of a process. setpriority # setpriority WHICH,WHO,PRIORITY set a process's nice value. setprotoent prepare protocols file for use. setpwent prepare passwd file for use. setservent prepare services file for use. setsockopt # setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL set some socket options. shift # shift ARRAY # shift removes the first element of an array, and returns it. shmctl # shmctl ID,CMD,ARG SysV shared memory operations. shmget # shmget KEY,SIZE,FLAGS get SysV shared memory segment identifier. shmread # shmread ID,VAR,POS,SIZE read SysV shared memory. shmwrite write SysV shared memory. shutdown # shutdown SOCKET,HOW close down just half of a socket connection. sin # sin EXPR return the sine of a number in radians. sleep # sleep EXPR # sleep block for EXPR number of seconds or forever if EXPR omitted. socket # socket SOCKET,DOMAIN,TYPE,PROTOCOL create a socket. socketpair # socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL create a pair of sockets. sort # sort SUBNAME LIST # sort BLOCK LIST # sort LIST sort a list of values in list context. If SUBNAME is specified, it's a subroutine that returns an integer less than, equal to, or greater than 0 , depending on how the elements of the list are to be ordered. splice # splice ARRAY,OFFSET,LENGTH,LIST # splice ARRAY,OFFSET,LENGTH # splice ARRAY,OFFSET # splice ARRAY Remove LENGTH elements from OFFSET in an array, and insert elements of LIST instead. split # split /PATTERN/,EXPR,LIMIT # split /PATTERN/,EXPR # split /PATTERN/ # split split up a string using a regexp PATTERN delimiter or whiltespace if omitted. sprintf # sprintf FORMAT, LIST Returns a formatted string. sqrt # sqrt EXPR # sqrt square root function. srand # srand EXPR # srand seed the random number generator. stat # stat FILEHANDLE # stat EXPR # stat Returns a 13-element list giving the status info for a file, either the file opened via FILEHANDLE, or named by EXPR. study # study SCALAR # study optimize input data for repeated searches. sub # sub NAME BLOCK # sub NAME (PROTO) BLOCK # sub NAME : ATTRS BLOCK # sub NAME (PROTO) : ATTRS BLOCK declare a subroutine, possibly anonymously. substr # substr EXPR,OFFSET,LENGTH,REPLACEMENT # substr EXPR,OFFSET,LENGTH # substr EXPR,OFFSET Extracts LENGTH (or all if omitted) characters from a string starting at OFFSET, and replaces them with REPLACEMENT if defined. symlink # symlink OLDFILE,NEWFILE create a symbolic link to a file. syscall # syscall NUMBER, LIST Calls the system call specified as the first element of the list, passing the remaining elements as arguments to the system call. sysopen # sysopen FILEHANDLE,FILENAME,MODE # sysopen FILEHANDLE,FILENAME,MODE,PERMS open a file, pipe, or descriptor and associates it with FILEHANDLE. sysread # sysread FLHNDLE,SCALAR,LENGTH,OFFSET # sysread FILEHANDLE,SCALAR,LENGTH Attempts to read LENGTH bytes of data into variable SCALAR from the specified FILEHANDLE. sysseek # sysseek FILEHANDLE,POSITION,WHENCE position I/O pointer on handle used with sysread and syswrite. system # system LIST # system PROGRAM LIST runs a separate program by forking it, and waits for the child process to complete. syswrite # syswrite FLHANDLE,SCALAR,LENGTH,OFFSET # syswrite FILEHANDLE,SCALAR,LENGTH # syswrite FILEHANDLE,SCALAR Attempts to write LENGTH bytes of data from variable SCALAR to the specified FILEHANDLE. tell # tell FILEHANDLE # tell gReturns the current position in bytes for FILEHANDLE. telldir telldir DIRHANDLE Returns the current position of the readdir routines on DIRHANDLE. tie # tie VARIABLE,CLASSNAME,LIST This function binds a variable to a package class that will provide the implementation for the variable. VARIABLE is the name of the variable to be enchanted. CLASSNAME is the name of a class implementing objects of correct type. Any additional arguments are passed to the new method of the class. tied # tied VARIABLE Returns a reference to the object underlying VARIABLE. time # time return number of seconds since midnight, Jan 1, 1970. times # times Returns a four-element list giving the user and system times, in seconds, for this process and the children of this process. tr # tr/SEARCHLIST/REPLACEMENTLIST/cds transliterate all characters in SEARCHLIST with corresponding characters from REPLACEMENTLIST. truncate # truncate FILEHANDLE,LENGTH # truncate EXPR,LENGTH shorten a file to specified LENGTH. uc # uc EXPR # uc returns upper-case version of a string. ucfirst # ucfirst EXPR # ucfirst returns a string with just the first letter in upper case. umask # umask EXPR # umask set file creation mode mask and returns the previous value. undef # undef EXPR # undef removes a variable or function definition. unlink # unlink LIST # unlink removes one link to a file (deletes it). unshift # unshift ARRAY,LIST prepends LIST elements to the beginning of an ARRAY. untie # untie VARIABLE breaks a tie binding to a variable. use # use Module VERSION LIST # use Module VERSION # use Module LIST # use Module # use VERSION loads in a module at compile time, and demands a certain VERSION of perl. utime # utime LIST Changes the access and modification times on each file of a list of files. values # values HASH returns a list of the values in a hash. vec # vec EXPR,OFFSET,BITS tests or sets particular bits in a string. wait # wait waits for any child process to die. waitpid # waitpid PID,FLAGS wait for a particular child process to die. wantarray # wantarray Returns true if the context of the currently executing subroutine or eval() block is looking for a list value. warn # warn LIST Produces a message on STDERR just like die, but doesn't exit or throw an exception. write # write FILEHANDLE # write EXPR # write Writes a formatted record (possibly multi-line) to the specified FILEHANDLE, using the format associated with that file. -r # -r FILE Test if file is readable by effective uid/gid. -w # -w FILE Test if file is writable by effective uid/gid. -x # -x FILE Test if file is executable by effective uid/gid. -o # -o FILE Test if file is owned by effective uid. -R # -R FILE Test if file is readable by real uid/gid. -W # -W FILE Test if file is writable by real uid/gid. -X # -X FILE Test if file is executable by real uid/gid. -O # -O FILE Test if file is owned by real uid. -e # -e FILE Test if file exists. -z # -z FILE Test if file has zero size (is empty). -s # -s FILE Test if file has nonzero size (returns size in bytes). -f # -f FILE Test if file is a plain file. -d # -d FILE Test if file is a directory. -l # -l FILE Test if file is a symbolic link. -p # -p FILE Test if file is a named pipe (FIFO), or Test if filehandle is a pipe. -S # -S FILE Test if file is a socket. -b # -b FILE Test if file is a block special file. -c # -c FILE Test if file is a character special file. -t # -t FILE Test if filehandle is opened to a tty. -u # -u FILE Test if file has setuid bit set. -g # -g FILE Test if file has setgid bit set. -k # -k FILE Test if file has sticky bit set. -T # -T FILE Test if file is an ASCII text file (heuristic guess). -B # -B FILE Test if file is a "binary" file (opposite of -T). -M # -M FILE Script start time minus file modification time, in days. -A # -A FILE Script start time minus file access time, in days. -C # -C FILE Script start time minus inode change time (Unix, may differ for other platforms) y # y/SEARCHLIST/REPLACEMENTLIST/cds transliterate all characters in SEARCHLIST with corresponding characters from REPLACEMENTLIST. * comment * Pragmas attributes Pragma: get/set subroutine or variable attributes. attrs Pragma: set/get attributes of a subroutine (deprecated). autouse Pragma: postpone load of modules until a function is used. base Pragma: Establish IS-A relationship with base classes at compile time. bigint Pragma: Transparent BigInteger support for Perl. bignum Pragma: Transparent BigNumber support for Perl. bigrat Pragma: Transparent BigNumber/BigRational support for Perl. blib Pragma: Use MakeMaker's uninstalled version of a package. bytes Pragma: force byte semantics rather than character semantics. charnames Pragma: define character names for \N{named} string literal escapes. constant Pragma: declare constants. diagnostics Pragma: produce verbose warning diagnostics. encoding Pragma: allows you to write your script in non-ascii or non-utf8. fields Pragma: compile-time class fields. filetest Pragma: control the filetest permission operators. if Pragma: use a Perl module if a condition holds. integer Pragma: use integer arithmetic instead of floating point. less Pragma: request less of something from the compiler. lib Pragma: manipulate @INC at compile time. locale Pragma: use and avoid POSIX locales for built-in operations. open Pragma: set default PerlIO layers for input and output. ops Pragma: restrict unsafe operations when compiling. overload Pragma: Package for overloading perl operations. re Pragma: alter regular expression behaviour. sigtrap Pragma: enable simple signal handling. sort Pragma: control sort() behaviour. strict Pragma: restrict unsafe constructs. subs Pragma: predeclare sub names. threads Pragma: Perl extension allowing use of interpreter based threads from perl. threads::shared Pragma: Perl extension for sharing data structures between threads. utf8 Pragma: enable/disable UTF-8 (or UTF-EBCDIC) in source code. vars Pragma: predeclare global variable names (obsolete). vmsish Pragma: control VMS-specific language features. warnings Pragma: control optional warnings. warnings::register Pragma: warnings import function. * comment * Guidelines object * ModuleName is ClassName Create an object: $obj = new ClassName (args); $obj = ClassName->new(args); $obj = $otherObj->creationFn(args); Call a method: $result = method $obj (args); $result = $obj->method(args); (use second form to avoid name resolution conflicts) An object variable is really a reference to a hash with an added class identifier, made when the object is "bless"ed. -- entia non sont multiplicanda praeter necessitatem. Guillaume d'Ockham.