in reply to What's your programming style?

My style is very different to each of the proposals:
my %SEPARATOR_BY_OS = ( darwin => ':', MSWin32 => '\\' ); sub get_pathname_separator { $SEPARATOR_BY_OS{$^O} // '/' }

See Platforms in perlport for the possible values of $^O. Note that MACOS isn't part of any value and that your solution would return \ on Mac OS X, as

index 'DARWIN', 'WIN' == 3

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: What's your programming style?
by Laurent_R (Canon) on Dec 08, 2018 at 18:55 UTC
    The document you refer to doesn't seem nor claim to be exhaustive.

    I don't have a Mac computer to check that, but it seems from other documents that $^O is equal to the "MacOS" string on a Mac computer (or, at least, it used to be so).

      The naming conventions are, at least in my opinion, easily confused. The use of spaces and capitalisation can make a lot of difference.

      For versions where $^O returns MacOS, see perlmacos (that's the most recent online perldoc [for 5.26.1]). Note the versions of Perl where support was dropped and then removed. See perlport (5.8.9) > PLATFORMS > Mac OS for historical information (including use of the ":" separator).

      Mac versions 10.x started roughly 20 years ago. They were originally called "Mac OS X". Around version 10.10 — I don't have exact information to hand — that became "macOS". (I don't know why.) They all use the "/" separator (same as any UNIX-like system).

      I have personal knowledge of versions from 10.7 "Mac OS X" to 10.12 "macOS" (I've used most but not all). To the best of my knowledge, for all of these versions, $^O has always returned darwin.

      $ perl -le 'print $^O' darwin

      Unless support for very old hardware is intended, coding for $^O returning MacOS is probably unnecessary (except, perhaps, for a warning about an unsupported operating system).

      — Ken

        Thank you, Ken, for the clarification. The documents on which I relied were from the year 2000 or so, that's why I prudently concluded my comment with the sentence "or, at least, it used to be so".

      Like others have said. It’s been 18 years since Mac started the move from 9 to X (a play on 10, uniX, and neXtstep). 17 years ago X was on all boxes with some dual/system boot options and a couple years after, 9 was gone. I was a dyed in wool Mac fan from the 80s (when all the good typesetting and music software was there) but by 1999 I was within a year of giving up on Mac for some kind of *nix when they made the leap, put out the beta, and I was allowed to remain in their camp.

      Salut, Laurent. Not for a long time has it been like that in my experience. I am on MacOS Sierra, but it's been darwin for as long as I can remember.

      $ perl -E 'say $^O' darwin $ perl -v This is perl 5, version 26, subversion 1 (v5.26.1) built for darwin-2l +evel $ uname -a Darwin MYHOSTNAME 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 21 20:0 +7:39 PDT 2018; root:xnu-3789.73.14~1/RELEASE_X86_64 x86_64

      See Re: Get macOS Version for recent discussion.


      The way forward always starts with a minimal test.

        Does this mean for modern Macs (MacOS) you can simply write Unix-like Perl, including Unix-like path names?

        Thank you, 1nickt, for the clarification.