perlspecial-variables

What is the dollar caret zero variable ( $^0 ) in Perl?


I've found some Perl code that makes the following check:

As displayed on the screen

if ($^O eq 'MSWin32')

What is the $^0 variable? It looks like it contains the architecture/OS of the machine it's running on, but I don't know if that's the result of assigning it elsewhere in the script (maybe it's the result of a regex match, though I can't see any match operations performed before that point), or whether that variable always has a value related to the machine it's running on.

I'd like to check the OS and bitness of the machine running the script, and would like to know if I can use $^0 to help me with that (if not, then I'm still curious what it is).

I'd rather not publish other parts of the Perl script, as it's proprietary.

This strikes me as the sort of question that should have been asked before, but Google isn't much use, thanks to the special characters (I often think the inability to Google Perl code led in part to its demise), and Stack Overflow doesn't have any useful suggested questions either.

There's no match for $^0 or $^1 or $^# on the perlvar page, and I'm not convinced that $^N or $^X are related.


Solution

  • It is not a zero.

    It is the letter "O", capitalized.

    In perlvar, search for OSNAME, which is the long form name of the variable when you use English:

    The name of the operating system under which this copy of Perl was built, as determined during the configuration process.

    There is no special "dollar caret zero" variable.