eWebProgrammer
Distributednetworks GofPatterns
prev prev
  Course navigation
  Perl Numeric literals
    Numeric literals can be specified in a number of different manners.
479            # simple integer
479.38         # simple real number
               # (floating point)
.23E-10        # scientific notation
0x01df         # hexadecimal
0377           # octal numbers have 
               #    a leading 0
4_294_967_296  # underscores are ignored  
               #    and can be used for
               #    legibility
All of the following declarations are equivalent:
$x = 479;      # decimal (base 10)
$x = 0x01df;   # hexadecimal (base 16)
$x = 0737;     # octal (base 8)
Note that a leading zero is used to specify octal, so the following two declarations are not equivalent:
$x = 473;
$x = 0473; # 473 octal is 315 in decimal!
Tip on Octal Numbers
Since 9 is not a valid digit in octal (0-7),
$x = 0479 will produce an error message.
What is the difference between these two lines of code?
$x = 374;
$x = 0374;
The first one is decimal and the second is octal. Remember, literal numbers that start with a zero are interpreted in octal (base 8).
  Course navigation