"Perl for Dumbasses" quiz, Labor Day edition

brian_d_foy on 2004-09-05T20:58:21

Here's a little portability quiz for you. Why doesn't this work?

... unless $^O =~ /win/i;


For bonus points, what do you think I was trying to do (just with the conditional)?

For super bonus points, which module do you think I look in when I use $^O?

Previous Dumbass episodes: 18881, 10182, 10091.

Remember, I'm making mistakes so you don't have to!

Okay, enough Perl for today. It's time for pre-Labor Day parties.


Portability

grantm on 2004-09-05T22:03:00

I'm guessing you wanted to match something like 'MSWin32' and not match something like 'Darwin'.

As to what operation you were going to skip if you weren't on Windows, my crystal ball isn't too clear. I used to skip flock on Win95/98/ME since it was (fatally) unsupported, but NT/XP etc do support flock. It's not binmode because you'd be using 'if' rather than 'unless' (or just doing it anyway on all platforms).

Re:Portability

brian_d_foy on 2004-09-05T22:10:00

Yep, that's it. I thought I was pretty slick with that /Win/ thing, until it didn't work on my Powerbook, which sets $^O to "darwin".

That's all. The operation I was trying to skip is no big whoop: just a test that won't work on Windows. It was the intent of the conditional that was interesting, and you got it. :)

Re:Portability

jhi on 2004-09-06T11:54:18

Also 'cygwin'.

Re:Portability

brian_d_foy on 2004-09-06T12:24:35

I'd want to skip that one too, though.

Re:Portability

jhi on 2004-09-06T13:09:50

> I'd want to skip that one too, though.

In the general case that's a tricky one, of course, since Cygwin can do quite many UNIX tricks, but also some Win32 tricks (and with libwin32 even more of the latter).