shelling out? - uname

Nik Clayton nik at ngo.org.uk
Fri Dec 8 14:28:14 GMT 2006


Hi Russ,

Russ Hogge wrote:
> Is there a good method of returning uname within perl.  I need to test if
> my script is running on Linux or Solaris, and suspect that there is a
> module that would tell me this information is a sane manner.
> 
> Clearly I could just type:
> chomp($platform = `/usr/bin/uname`);
> 
> But this strikes me as poor.
> 
> Any thoughts?

For the specific case you describe, then the special variable $^O should do it.

   % perl -e 'print "$^O\n"';
   freebsd

More generally, stuff that Perl finds when it was built is stuffed in to 
Config.pm.  So you could also do:

   % perl -MConfig -e 'print $Config{osname}, "\n";'
   freebsd

($Config{osname} and $^O being identical).  %Config has other keys though. 
For example:

   % perl -MConfig -e 'print $Config{osvers}, "\n"';
   5.4-release

which might also be helpful.

N



More information about the london.pm mailing list