views:

102

answers:

3

I'm looking for a simple way to determine whether a system is 32- or 64-bit from within Perl 5. I have read the perlvar manual page backwards and forwards, and have not discovered a variable that contains the system's CPU architecture (the CPU architecture Perl was compiled for will come close enough). This is the closest I have come:

chomp (my $arch = `uname -m`);

I was wondering if there was a more elegant way of determining this; I hate relying on backtick expressions, as they are both a bottleneck, tend to be insecure, and often (this example especially) break cross-platform compatibility. There is no reason Perl shouldn't already have this information available.

+8  A: 

See the Config module.

Maybe checking whether $Config{'archname64'} is set would be sufficient.

mobrule
This might be one of those "what do you really want to know?" questions. For struct en/decoding you might want to inspect `$Config{alignbytes}` or `$Config{byteorder}`; if you're interested in integer range you might want `$Config{intsize}` or `$Config{ivsize}` (which I think is relatively new), etc. etc.
hobbs
+1  A: 

Maybe try a CPAN module such as http://search.cpan.org/dist/Devel-CheckOS/ .

Shlomi Fish
+4  A: 

Sys::Info::OS->bitness method will determine "bitness" of your OS.

Alexandr Ciornii