Numbers

Although a scalar is either a number or a string,[22] consider numbers and strings separately for the moment. Numbers first, strings in a minute...

All Numbers Use the Same Format Internally

As you’ll see in the next few paragraphs, you can specify both integers (whole numbers, like 17 or 342) and floating-point numbers (real numbers with decimal points, like 3.14, or 1.35 times 1025). But internally, Perl computes only with double-precision floating-point values.[23] This means that there are no integer values internal to Perl; an integer constant in the program is treated as the equivalent floating-point value.[24] You probably won’t notice the conversion (or care much), but you should stop looking for integer operations (as opposed to floating-point operations), because there aren’t any.

Float Literals

A literal is the way a value is represented in the text of the Perl program. You could also call this a constant in your program, but we’ll use the term literal. Literals are the way in which data is represented in the source code of your program as input to the Perl compiler. (Data that is read from or written to files is treated similarly, but not identically.)

Perl accepts the complete set of floating-point literals available to C programmers. Numbers with and without decimal points are allowed (including an optional plus or minus prefix), as well as tacking on a power-of-10 indicator ( exponential notation) with E notation (that’s e or E). For example:

1.25 # about 1 and ...

Get Learning Perl on Win32 Systems now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.