Perl - easy way to get 64 bit containers (and beyond) - bigint, bignum.

You can pretty much do anything you want in Perl but sometimes the trick is to do it easily and with a minimum of hassle.

I often use Perl scripts to parse output I've taken from embedded applications. If the embedded application uses 64 bit values and you want to do arithmetic operations on those values (shifts, masks, add, multiplies, divides) Perl will by default assume 32 bit containers and you won't get the answer you want.


use bigint;
use bignum;

Use the first if you need integer representations and the second if you need floating point behavior (I needed to calculate some percentages which required me to use bignum.)

The beauty is one line of perl code and you're done - no complicated libraries, no getting modules from CPAN, just simplicity itself. Maybe most folks already know this but it was new to me so I thought I'd share. Apparently you're not limited to 64 bits either - I have not tested this however.

My perl version was as follows:

perl -v

This is perl, v5.8.5 built for x86_64-linux-thread-multi
Post a Comment

Popular posts from this blog

Hit failing alternator with a hammer to confirm diagnosis of failing alternator due to bad brushes

alternatives --install gets stuck: failed to read link: No such file or directory

Using SSH, SOCKS, tsocks, and proxy settings to create a simultaneous "dual use" work/home computer