Elegant definition of system architecture in Perl

I'm looking for an easy way to determine if a system is 32-bit or 64-bit from Perl 5. I read the manual perlvar page back and forth and did not find a variable containing the CPU architecture of the system (the Perl processor architecture was compiled to get close enough). This is the closest I came:

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

I was wondering if there was a more elegant way to define this; I hate relying on backward expressions because they are both a bottleneck, generally unsafe, and often (especially this example) violate cross-platform compatibility. There is no reason Perl should not have this information.

+6
perl architecture
source share
4 answers

See the Config module.

Checking for the presence of $Config{'archname64'} might be sufficient.

+10
source share

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

+7
source share

Perhaps try the CPAN module, for example https://metacpan.org/pod/Devel::CheckOS .

+2
source share

You can use the POSIX module, which provides a uname function similar to the uname utility.

 use POSIX (); my ($sysname, $nodename, $release, $version, $machine) = POSIX::uname; 

Or, in your case:

 my $arch = (POSIX::uname)[4]; 
0
source share

All Articles