[prev] [index] [next]

Scalars (cont)

Examples:

$x = '123';    # $x assigned string "123"
$y = "123 ";   # $y assigned string "123 "
$z = 123;      # $z assigned integer 123
$i = $x + 1;   # $x value converted to integer
$j = $y + $z;  # $y value converted to integer
$a = $x == $y; # compare numeric versions of $x,$y  (true)
$b = $x eq $y; # compare string versions of $x,$y   (false)
$c = $x.$y;    # concat string versions of $x,$y (explicit)
$c = "$x$y";   # concat string versions of $x,$y (interpolation)

Note: $c = $x $y is invalid (Perl has no empty infix operator)

(cf. awk, where $x $y means string concatenation)