Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Perl >> Snippet

06 Operators


0     is False
"0"   is False
""    is False
undef is False

all else is True

print True;    # prints a blank
print False;   # prints a blank

undef      # variables which have not been set have a value of undef
          # using -w will catch
          # some functions return undef on failure

Numeric:
$x == $y    True if $x equals $y
$x > $y
$X < $y
$x >= $y
$x <= $y
$x != $y  True is $x is not equal to $y

AlphaNumeric:
$x eq $y
$x gt $y
$x lt $y
$x ge $y
$x le $y
$x ne $y

Logical Operators:

and /Or/ not can each be written in two ways:
&&    and        #  $a && $b     $a and $b
||    or         #  $a || $b     $a or $b
!     not        #  ! $b      not $b

Special operators:
$c ++             # same as $c = $c + 1
$c --             # same as $c = $c - 1
$a += 3            # same as $a = $a + 3
$y *= $x           # same as $y = $y * $x
$r% = 67           # same as $r = $r % 67

qq ()             # quote-quote (double quotes)
q ()              # quote (single quote - no interpolation)
qw ()             # list with no interpolation (uses whitespace to separate list items)
$ #myarray       # used to resize @myarray