[prev] [index] [next]

Scalars (cont)

Scalars are converted to printable form when interpolated into strings.

A couple of subtleties to note:

  • for booleans ... true 1,   false "".
  • for numbers ... Perl uses the default format %.15g
Numeric formatting produces the most compact representation it can with up to 15 significant digits, e.g.

$x = 3/2; print "$x";  # displays 1.5
$x = 4/2; print "$x";  # displays 2
$x = 1/3; print "$x";  # displays 0.333333333333333

To get numbers formatted exactly how you want ... use printf.