I had the same problem and came across a solution that gcc uses. For various reasons this is expressed as a bash script and a more recent version is probably abailable. I leave the conversion to Perl as an exercise for the reader:

# Short circuit this function if we know which system we are on if [ $OS_SYSTEM_REALLY ]; then echo "${OS_SYSTEM_REALLY}" return fi # First get the values for this machine # Code lifted from config.guess in the gcc software OS_UNAME_M=`(uname -m) 2>/dev/null` || OS_UNAME_M=unknown OS_UNAME_S=`(uname -s) 2>/dev/null` || OS_UNAME_S=unknown OS_UNAME_R=`(uname -r) 2>/dev/null` || OS_UNAME_R=unknown OS_UNAME_V=`(uname -v) 2>/dev/null` || OS_UNAME_V=unknown OS_UNAME="${OS_UNAME_M}:${OS_UNAME_S}:${OS_UNAME_R}:${OS_UNAME_V}" # Note: order is significant - the case branches are not exclusive +. case "${OS_UNAME}" in sun4*:SunOS:5.[012345]*:*) echo "sol24" return ;; sun4*:SunOS:5.[6789]*:*) echo "sol26" return ;; sun4*:SunOS:[7891]*:*) echo "Unknown Solaris version" >&2 echo "Try setting \$OS_SYSTEM_REALLY to sol26" >&2 echo "unknown" return ;; sun4*:SunOS:*:*) echo "sun" return ;; *:AIX:1:4) echo "aix41" return ;; *:IRIX*:5.*:*) echo "sgi" return ;; *:IRIX*:6.[2345]:*) echo "irix62" return ;; 9000/[78]??:HP-UX:*:*) echo "hp" return ;; i[345678]86:Linux:*:*) echo "linux" return ;; sparc:Linux:*:*) echo "ulinux" return ;; *:*:*:*) # If we get here then we have something weird echo "Unknown system \"${OS_UNAME}\"" >&2 echo "Try setting \$OS_SYSTEM_REALLY to one of sun, sol, h +p etc" >&2 echo "unknown" return ;; esac

In reply to Re: Backward compatibility: $^O in perl 4 by hawtin
in thread Backward compatibility: $^O in perl 4 by bronto

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.