Gossamer Forum
Home : General : Perl Programming :

Work out if on a UNIX, or NT server...

Quote Reply
Work out if on a UNIX, or NT server...
Hi. Does anyone have a 'safe' method to work out if a script is running on a UNIX, or NT server?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Work out if on a UNIX, or NT server... In reply to
Look in perldoc perlvar

http://www.perldoc.com/...8.0/pod/perlvar.html

Scroll down to $^0

- wil
Quote Reply
Re: [Wil] Work out if on a UNIX, or NT server... In reply to
Thanks... it worked like a charm:)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Wil] Work out if on a UNIX, or NT server... In reply to
You know, I've used $^O before but never thought to look at the win32 modules for further information (I program perl stuff for windows pretty infrequently)

Something like this would actually be pretty useful when doing cross platform coding, me thinks. :)

Code:
if ('MSWin32' eq $^O)
{
require Win32;

my $version = Win32::GetOSName();
# ... do stuff based on specific windows version ...
}

I'll have to remember that for next time
--mark
Quote Reply
Re: [Mark Badolato] Work out if on a UNIX, or NT server... In reply to
>>>('MSWin32' eq $^O) <<<


Isn't that the wrong way? Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Work out if on a UNIX, or NT server... In reply to
nope it will work fine. it's especially useful when you're doing == comparisons because doing it like this will imediatly generate a warning if you accidently use = instead of ==. Saves a lot of time tracking down bugs like that... :)

try it.. run

Code:
if ($foo = 2)
{
# Do something
}

vs

Code:
if (2 = $foo)
{
# Do something
}
just a tip that's been picked up over the years. again, not so much for when doing eq in perl, but nonetheless a habit i've gotten into

Last edited by:

Mark Badolato: Aug 25, 2003, 8:06 AM
Quote Reply
Re: [Mark Badolato] Work out if on a UNIX, or NT server... In reply to
If you program under -w, you'll see a warning the other way:

[alex@penguin ghost]$ perl -we 'if ($foo = 2) { }'
Found = in conditional, should be == at -e line 1.
Name "main::foo" used only once: possible typo at -e line 1.
[alex@penguin ghost]$

=)

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Work out if on a UNIX, or NT server... In reply to
Yup, however i still like it becuase it helps catch things in other languages too :)