in reply to Get macOS Version

That information should be easily accessible using System::Info, which should work on most (if not all) supported OS's:

$ perl -MData::Dumper -MSystem::Info=sysinfo_hash -wE'print Dumper (sy +sinfo_hash)' $VAR1 = { 'cpu_cores' => '2', 'cpu' => 'Mac mini (2 GHz)', 'hostname' => 'myhostname.local', 'osname' => 'Darwin', 'distro' => 'Darwin 17.0.0', 'cpu_type' => 'x86_64', 'osvers' => '17.0.0', 'os' => 'darwin - 17.0.0 (Mac OS X - macOS 10.13 (17A365))', 'cpu_count' => '1 [2 cores]' };

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: Get macOS Version
by 1nickt (Canon) on Oct 26, 2018 at 12:50 UTC

    Hi Tux, it looks like there 'osvers' also means 'build version', rather than 'OS version,' and the string that the OP needs ("10.13") is buried in the 'os' value. Of course one could fish it out of there, but in this case I think I prefer the simplicity of a shell call: qx/sw_vers -productVersion/. If the function had to be portable, I might use the module you show, but with the parsing code needed for each OS, it seems like one might as well have conditionally executed shell calls.


    The way forward always starts with a minimal test.

      Mea culpa, mea maxima culpa for waiting so long to implement something so simple. I needed access to a Mac to test it, but it is just released as 0.059:

      mac01 $ perl -Mblib examples/sysinfo.pl -- from methods Distname : mac01.local darwin - 17.0.0 (Mac OS X - macOS 1 +0.13 (17A365)) Mac mini (2 GHz) 1 [2 cores] x86_64 Hostname : mac01.local Number of CPU's : 1 [2 cores] Processor type : x86_64 Processor description: Mac mini (2 GHz) OS and version : darwin - 17.0.0 (Mac OS X - macOS 10.13 (17A365 +)) -- from hash cpu : Mac mini (2 GHz) cpu_cores : 2 cpu_count : 1 [2 cores] cpu_type : x86_64 distro : Darwin 10.13 hostname : mac01.local os : darwin - 17.0.0 (Mac OS X - macOS 10.13 (17A365 +)) osname : Darwin osvers : 10.13

      Enjoy, Have FUN! H.Merijn