home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


7.2.38 integer - Do Arithmetic in Integer Instead of Double

use integer;

$x = 10/3;   # $x is now 3, not 3.33333333333333333

This module tells the compiler to use integer operations from here to the end of the enclosing block. On many machines, this doesn't matter a great deal for most computations, but on those without floating point hardware, it can make a big difference.

This pragma does not automatically cast everything to an integer; it only forces integer operations on arithmetic. For example:

use integer; 
print sin(3);           # 0.141120008059867
print sin(3) + 4;       # 4

You can turn off the integer pragma within an inner block by using the no integer directive.


Previous: 7.2.37 I18N::Collate - Compare 8-bit Scalar Data According to the Current Locale Programming Perl Next: 7.2.39 IPC::Open2 - Open a Process for Both Reading and Writing
7.2.37 I18N::Collate - Compare 8-bit Scalar Data According to the Current Locale Book Index 7.2.39 IPC::Open2 - Open a Process for Both Reading and Writing