tags:

views:

94

answers:

4

I remember having used the variable $OSNAME in linux.

Currently I'm working on a project on Solaris where I need to get the OS name and that variable is not working on Solaris.

Even a simple one line program does not work:

print "OS is $OSNAME\n";

it prints

OS is

Please help.

+14  A: 

You need to use the English module.

$OSNAME is actually an alias for $^O, you can use $^O without using English module but to use $OSNAME you need to use the English module.

Also since use strict is missing you did not get any errors.

Always use use strict; in your program, it will help you catch these kinds of errors.

So try:

use English;
use strict;

print "Operating system is $OSNAME\n";
codaddict
Always use English qw(-no_match_vars); or it slows you program down
+2  A: 

You can use print $^Oinstead.

kriss
+2  A: 

Testing stuff from the command line, I get:

$ perl -E 'say $OSNAME'

$ perl -Mstrict -E 'say $OSNAME'
Global symbol "$OSNAME" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors.
$ perl -Mstrict -MEnglish -E 'say $OSNAME'
linux
davorg
+2  A: 

If $OSNAME ($^O) doesn't contain precisely the information you need, take a look at the values available to you from the Config module.

Ether