substr

substr EXPR,OFFSET,LENGTH,REPLACEMENT substr EXPR,OFFSET,LENGTH substr EXPR,OFFSET Extracts a substring out of EXPR and returns it. First character is at offset zero. If OFFSET is negative, starts that far back from the end of the string. If LENGTH is omitted, returns everything through the end of the string. If LENGTH is negative, leaves that many characters off the end of the string. my $s = "The black cat climbed the green tree"; my $color = substr $s, 4, 5; # black my $middle = substr

subs - Perl pragma to predeclare sub names

NAME SYNOPSIS DESCRIPTION NAME subs - Perl pragma to predeclare sub names SYNOPSIS use subs qw(frob); frob 3..10; DESCRIPTION This will predeclare all the subroutine whose names are in the list, allowing you to use them without parentheses even before they're declared. Unlike pragmas that affect the $^H hints variable, the use vars and use subs declarations are not BLOCK-scoped. They are thus effective for the entire package in which they appear. You may not rescind such declarations with no

sub

sub NAME BLOCK sub NAME (PROTO) BLOCK sub NAME : ATTRS BLOCK sub NAME (PROTO) : ATTRS BLOCK This is subroutine definition, not a real function per se. Without a BLOCK it's just a forward declaration. Without a NAME, it's an anonymous function declaration, so does return a value: the CODE ref of the closure just created. See perlsub and perlref for details about subroutines and references; see attributes and Attribute::Handlers for more information about attributes.

study

study SCALAR study May take extra time to study SCALAR ($_ if unspecified) in anticipation of doing many pattern matches on the string before it is next modified. This may or may not save time, depending on the nature and number of patterns you are searching and the distribution of character frequencies in the string to be searched; you probably want to compare run times with and without it to see which is faster. Those loops that scan for many short constant strings (including the constant par

strict - Perl pragma to restrict unsafe constructs

NAME SYNOPSIS DESCRIPTION HISTORY NAME strict - Perl pragma to restrict unsafe constructs SYNOPSIS use strict; use strict "vars"; use strict "refs"; use strict "subs"; use strict; no strict "vars"; DESCRIPTION If no import list is supplied, all possible restrictions are assumed. (This is the safest mode to operate in, but is sometimes too strict for casual programming.) Currently, there are three possible things to be strict about: "subs", "vars", and "refs". strict refs This generates a

Storable - persistence for Perl data structures

NAME SYNOPSIS DESCRIPTION MEMORY STORE ADVISORY LOCKING SPEED CANONICAL REPRESENTATION CODE REFERENCES FORWARD COMPATIBILITY ERROR REPORTING WIZARDS ONLYHooks Predicates Recursion Deep Cloning Storable magic EXAMPLES SECURITY WARNING WARNING BUGS64 bit data in perl 5.6.0 and 5.6.1 CREDITS AUTHOR SEE ALSO NAME Storable - persistence for Perl data structures SYNOPSIS use Storable; store \%table, 'file'; $hashref = retrieve('file'); use Storable qw(nstore store_fd nstore_fd freeze thaw dclon

state

state VARLIST state TYPE VARLIST state VARLIST : ATTRS state TYPE VARLIST : ATTRS state declares a lexically scoped variable, just like my. However, those variables will never be reinitialized, contrary to lexical variables that are reinitialized each time their enclosing block is entered. See Persistent Private Variables in perlsub for details. If more than one variable is listed, the list must be placed in parentheses. With a parenthesised list, undef can be used as a dummy placeholder. Howev

stat

stat FILEHANDLE stat EXPR stat DIRHANDLE stat Returns a 13-element list giving the status info for a file, either the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is omitted, it stats $_ (not _ !). Returns the empty list if stat fails. Typically used as follows: ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($filename); Not all fields are supported on all filesystem types. Here are the meanings of the fields: 0 dev

srand

srand EXPR srand Sets and returns the random number seed for the rand operator. The point of the function is to "seed" the rand function so that rand can produce a different sequence each time you run your program. When called with a parameter, srand uses that for the seed; otherwise it (semi-)randomly chooses a seed. In either case, starting with Perl 5.14, it returns the seed. To signal that your code will work only on Perls of a recent vintage: use 5.014; # so srand returns the seed If sran

sqrt

sqrt EXPR sqrt Return the positive square root of EXPR. If EXPR is omitted, uses $_ . Works only for non-negative operands unless you've loaded the Math::Complex module. use Math::Complex; print sqrt(-4); # prints 2i