"What is important is 16.7.0 and so on."

Are you sure about that? 16.7.0 (and darwin) refer to the Kernel Version:

[Note: I'm using Sierra 10.12.5.]

$ system_profiler SPSoftwareDataType Software: System Software Overview: System Version: macOS 10.12.5 (16F73) Kernel Version: Darwin 16.6.0 ...

It sounds like you really want the System Version. If so, and you only want the version number, this might be easier:

$ sw_vers -productVersion 10.12.5

To get at this information, you can use backticks, qx{}, open with '-|' mode, and other methods (the open doco has links to some of these). And, of course, add appropriate error handling.

Mac::OSVersion (already suggested by ++marto) uses both of those commands with backticks. It also provides a name() method; however, the names are hard-coded:

my @names = qw( Cheetah Puma Jaguar Panther Tiger Leopard ) ; push @names, 'Snow Leopard', 'Lion', 'Mountain Lion', 'Mavericks', 'Yosemite', 'El Capitan', 'Sierra', 'High Sierra', 'Mojave';

There's a potential problem with this. When Apple releases a new (named) version, that module will need to be updated, you'll need to upgrade to that updated version, and your users may need a similar upgrade.

If you wanted to handle the names yourself, https://support.apple.com/en-us/HT201260 has a list of names and version numbers. It looks like this information is kept up-to-date: it was last updated a month ago.

— Ken


In reply to Re^3: Get macOS Version by kcott
in thread Get macOS Version by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.