Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Perl's $OSNAME work on Solaris?

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.

like image 815
user463596 Avatar asked Dec 02 '25 08:12

user463596


1 Answers

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";
like image 98
codaddict Avatar answered Dec 03 '25 21:12

codaddict



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!