Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi: Is there any perl API which gives whether a unix system is 32 bit or 64 bit. Thanks, Tony
  • Comment on Perl API for 32 bit or 64 bit system on Unix

Replies are listed 'Best First'.
Re: Perl API for 32 bit or 64 bit system on Unix
by Thelonius (Priest) on May 12, 2004 at 16:21 UTC
    length(pack "i", 0) gives the length of the C "int" type.

    length(pack "p", "0") gives the length of a pointer

Re: Perl API for 32 bit or 64 bit system on Unix
by periapt (Hermit) on May 12, 2004 at 16:05 UTC
    I don't know how you might find out directly. You could try perl -V which will give you a complete configuration summary for your version of perl. Its kind of indirect evidence but often informative.

    using perl -V, you will get osname, osversion and archname which should give you a good idea of what platform your version of perl was compiled for. "use64bitint", "use64bitall", "intsize" will all help determine how you can use perl on the platform (use 64bitint = undef for 32 bit platform and intsize = 8 for 64 bit).

    Hope that helps
    PJ
      how to find out directly
      use Config qw/config_vars/;
      then examine
      $use64bitint $use64bitall $uselongdouble
      etc...
        This is not correct, since you can build perl with 64bit support on 32bit machines.
Re: Perl API for 32 bit or 64 bit system on Unix
by hawtin (Prior) on May 13, 2004 at 09:57 UTC

    Here's a thought, try

    $prog_name = eval("\$\x18"); # $^X $exec_type = `file $prog_name`; if($exec_type =~ /32/) { print "32 bit\n"; } elsif($exec_type =~ /64/) { print "64 bit\n"; } else { print "Cant unpick from $exec_type\n" }

    (Untested code)

    This would be if you are worried about linking to shared libraries (eg a 32 bit version of Perl won't load a 64 bit shared library under Solaris)

    Update: Corrected stupid use of $0 to $^X