Identifying the OS in a Perl script

Stephen R Laniel steve at laniels.org
Thu Sep 1 15:24:11 UTC 2005


I'm writing a Perl script that I'll need to be portable
across OSes. This is Perl's great virtue, of course. But
it's going to be running under cygwin when in Windows, and
I'll need some paths in there to be different: I'll need it
to save to c:\Documents and Settings\Username\foo, for
instance, whereas under Linux and OS X I'll need it to
save in ~foo.

So what I'd like is to be able to do something like so in
the script:

my $path = '';
if( $someVar == "Windows" ) {
	$path = 'c:\Documents And Settings\Username\foo';
}
elsif( $someVar == "Linux" ) {
	$path = '~Username';
}
elsif {
	...
}

Does anyone know the best way to handle this?

Likewise, under cygwin the Perl interpreter is stored in
c:\cygwin\bin\perl.exe, which is /bin/perl.exe; under Linux,
it's stored in /usr/bin/perl. So is there any way to have a
platform-specific "shebang" line, e.g.,

if( $someVar == "cygwin" ) {
	#!/bin/perl.exe
}
elsif( $someVar == "Linux" ) {
	#!/usr/bin/perl
}

? Thanks for any advice.

-- 
Stephen R. Laniel
steve at laniels.org
+(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20050901/76db14db/attachment.sig>


More information about the ubuntu-users mailing list