2
print "$^O\n";

returns

MSWin32

However, my laptop is 64-bit. Any idea if the Perl system call retrieves wrong data (by its or Windows' bug) or is it as designed?

amphibient
  • 29,770
  • 54
  • 146
  • 240

2 Answers2

5

Win32 is just the standard Windows API. This has little connection to 32-bit/64-bit processors or OS variants.

From perldoc -v $^O:

In Windows platforms, $^O is not very helpful: since it is always "MSWin32", it doesn't tell the difference between 95/98/ME/NT/2000/XP/CE/.NET. Use Win32::GetOSName() or Win32::GetOSVersion() (see Win32 and perlport) to distinguish between the variants.

On my system, it isn't very helpful either; returning just a plain linux ;-)

amon
  • 57,091
  • 2
  • 89
  • 149
  • 1
    i only need to differentiate whether the OS is Win or Linux so Win32 is fine (no difference in my script between 32 and 64 bit archs) but it just got my attention so i wanted to ask. i don't really need `Win32::GetOSName()` functionally, was just curious – amphibient Feb 14 '13 at 20:01
3

$^O is always MSWin32 on Windows.

If you want to know more about the system on which perl runs, you can use

use Win32;
print Win32::GetOSDisplayName(), "\n";
print Win32::GetOSName(), "\n";
print Win32::GetOSVersion(), "\n";

If you want to know the architecture for which perl was built, you can use

use Config qw( $Config );
print "$Config{archname}\n";

If you want to know the size of integers, you can use

use Config qw( $Config );
print $Config{ivsize}*8, " bits\n";
ikegami
  • 367,544
  • 15
  • 269
  • 518