Scalar Operations

Pattern Matching   Logical Operators   Arithmetic Operators   String Operations   Assignment Operators   File Operations  


Pattern Matching
Operator Operation Result
$a =~ /pat/ match True if $a contains pattern
$a =~ s/p/r/ substitution Replace contents of p with r in $a
$a =~ tr/a-z/A-Z/ translation Translate to corresponding characters
Return to Top

Logical Operators
Operator Operation Result
$a && $b And True if $a is true and $b is true
$a || $b Or $a if $a is true, otherwise $b
! $a Not True if $a is not true
Return to Top

Arithmetic Operators
Return to Top

String Operators
Operator Operation Result
$a + $b Add Sum of $a and $b
$a - $b Subtract Difference of $a and $b
$a * $b Multiply Product of $a times $b
$a / $b Divide Quotient of $a divided by $b
$a % $b Modulus Remainder of $a divided by $b
$a ** $b Exponent $a to the power $b
++$a
$a++
Autoincrement Add 1 to $a
--$a
$a--
Autodecrement Subtract 1 from $a
rand $a Random A random number in range 0 .. $a
abs $a Absolute Returns the absolute value of $a
cos $a Cosine Returns the cosine of $a
sin $a Sine Returns the sine of $a
exp $a e Exponent Returns e to the power of $a
int($a) Integer Returns the integer portion of $a
log $a Natural log Returns the natural log of $a
not $a Not
Negate
Logicl negative of $a
sqrt $a Square Root Returns the square root of $a
srand $a Seed Set the random number seed
time $a Seconds Returns the number of non-leap seconds since epoch
Operator Operation Result
$a . $b Concatenation Values of $a and $b as one long string
$a x $b Repeat Value of $a strung together $b times
substr($a,$o,$l) Substring Substring at offset $o of length $l
index($a,$b) Index Offset of string $b in string $a
chomp $a Chomp Removethe carrage return from the end of $a
chop $a Chop Returns the last character in $a
crypt ($a, $s) Encrypt Returns the DES encryption of $a using $s as salt
index ($a, $so, $o)
rindex ($a, $s, $o)
Index Returns the position of $s in $a offset by $o
index has offset from start of string
rindex has offset from end of string
lc $a
lcfirst $a
Lower case Makes $a lower case
Only the first character lower case
uc $a
ucfirst $a
Upper case Makes $a upper case
Only the first character upper case
length $a Length Returns the length of $a
quotemeta $a Quote Value of $a is returned with a "\" before all non-alpha characters
substr ($a, $o, $l)
substr ($a, $o, $l, $n)
Extract
Replace
Returns the sub-string of $a starting at $o the sub-string will be $l characters
Replaces the string $a with $n
Return to Top

Assignment Operators
Operator OperationResult
$a = $b Assign $a gets the value of $b
$a += $b Add to Increase $a by $b
$a -= $b Subtract from Decrease $a by $b
$a .= $b Append Append string $b to $a
Return to Top

File Test Operators
Operator OperationResult
-r $a Readable File name in $a is readable by effective uid
-w $a Writable Writable by effective uid
-x $a Executable Executable by effective uid
-o $a Owned Owned by effective uid
-R $a Readable Readable by real uid
-W $a Writable Writable by real uid
-X $a Executable Executable by real uid
-O $a Owned Owned by real uid
-e $a Exists File exists
-z $a Non-zero size File has non-zero size (returns size in bytes)
-s $a Zero size File has zero size
-f $a Regular file File is a regular file
-d $a Directory File is a directory
-l $a Symbolic link File is a symbolic link
-p $a Named pipe File is a named pipe (FIFO)
-S $a Socket File is a socket
-b $a Block File is a block special file
-c $a Character File is a character special file
-u $a UID File has setuid bit set
-g $a GID File has setgid bit set
-k $a Sticky bit File has sticky bit set
-T $a Text file File is a text file
-B $a Binary File is a binary file (opposite of -T)
-M $a Modify Age of file (at startup) in days since modification
-A $a Last Access Age of file (at startup) in days since last access
-C $a Inode change Age of file (at startup) in days since inode change
Return to Top