Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Operating Systems References?

Status
Not open for further replies.

Kirsle

Programmer
Jan 21, 2006
1,179
US
In programming applications for multiple operating systems, sometimes it's useful to know what certain Perl variables would equal on the different operating systems.

Does anybody know of a link to someplace that has the values of all of these, like in a table?

For example... something along the lines of...

Code:
Var      Windows            Linux       Unix   MacOS
---      -------            -----       ----   -----
$^O      MSWin32            linux       ???    ???
HomeDir  $ENV{USERPROFILE}  $ENV{HOME}  ???    ???

So... i.e. having a list of some of the OS-specific special variables, like $^O, and also the environment variables for common things such as user profiles.

For instance, $ENV{HOME} doesn't exist on Windows. On Linux, it'd be something like "/home/user", but on Windows, the only equivalent is $ENV{USERPROFILE}, which is something like "C:/Documents and Settings/user"

Anybody know if there are any reference tables for this kind of thing out there, or do I have to be the first one to make one?

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
I have never seen such a list myself. I have seen semi-lists in programs, like in the CGI module:

Code:
unless ($OS) {
    unless ($OS = $^O) {
	require Config;
	$OS = $Config::Config{'osname'};
    }
}
if ($OS =~ /^MSWin/i) {
  $OS = 'WINDOWS';
} elsif ($OS =~ /^VMS/i) {
  $OS = 'VMS';
} elsif ($OS =~ /^dos/i) {
  $OS = 'DOS';
} elsif ($OS =~ /^MacOS/i) {
    $OS = 'MACINTOSH';
} elsif ($OS =~ /^os2/i) {
    $OS = 'OS2';
} elsif ($OS =~ /^epoc/i) {
    $OS = 'EPOC';
} elsif ($OS =~ /^cygwin/i) {
    $OS = 'CYGWIN';
} else {
    $OS = 'UNIX';
}

I can see where such a list would be a handy tool for programmers.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Kirsle

Sounds like a candidate for a FAQ...

If you want to post a program that lists all the variables you are interested in, we could all run it on our respective OSs. Then all you'd have to do would be to collate the results. I can do Fedora 6, Win2K, and WinXP, if it's any help. Here's a starter for 10, although you'd probably want to specify the hash keys explicitly.
Code:
#!/usr/bin/perl -w
use strict;
use warnings;

print '$ENV{', $_, '} = ', $ENV{$_}, "\n" foreach sort keys %ENV;

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Another module that has a good list is File::Spec. The module itself is also useful since it has both the rootdir, tmpdir, and devnull generic references. No home dir though, but at the very least you could use the list of OS's.

Full code of File::Spec (missing only the pod):

Code:
[url=http://perldoc.perl.org/functions/package.html][black][b]package[/b][/black][/url] [green]File::Spec[/green][red];[/red]

[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]strict[/green][red];[/red]
[black][b]use[/b][/black] [green]vars[/green] [red]qw([/red][purple]@ISA $VERSION[/purple][red])[/red][red];[/red]

[blue]$VERSION[/blue] = [red]'[/red][purple]3.25[/purple][red]'[/red][red];[/red]
[blue]$VERSION[/blue] = [url=http://perldoc.perl.org/functions/eval.html][black][b]eval[/b][/black][/url] [blue]$VERSION[/blue][red];[/red]

[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]%module[/blue] = [red]([/red][purple]MacOS[/purple]   => [red]'[/red][purple]Mac[/purple][red]'[/red],
	      [purple]MSWin32[/purple] => [red]'[/red][purple]Win32[/purple][red]'[/red],
	      [purple]os2[/purple]     => [red]'[/red][purple]OS2[/purple][red]'[/red],
	      [purple]VMS[/purple]     => [red]'[/red][purple]VMS[/purple][red]'[/red],
	      [purple]epoc[/purple]    => [red]'[/red][purple]Epoc[/purple][red]'[/red],
	      [purple]NetWare[/purple] => [red]'[/red][purple]Win32[/purple][red]'[/red], [gray][i]# Yes, File::Spec::Win32 works on NetWare.[/i][/gray]
	      [purple]symbian[/purple] => [red]'[/red][purple]Win32[/purple][red]'[/red], [gray][i]# Yes, File::Spec::Win32 works on symbian.[/i][/gray]
	      [purple]dos[/purple]     => [red]'[/red][purple]OS2[/purple][red]'[/red],   [gray][i]# Yes, File::Spec::OS2 works on DJGPP.[/i][/gray]
	      [purple]cygwin[/purple]  => [red]'[/red][purple]Cygwin[/purple][red]'[/red][red])[/red][red];[/red]


[black][b]my[/b][/black] [blue]$module[/blue] = [blue]$module[/blue][red]{[/red][blue]$^O[/blue][red]}[/red] || [red]'[/red][purple]Unix[/purple][red]'[/red][red];[/red]

[url=http://perldoc.perl.org/functions/require.html][black][b]require[/b][/black][/url] [red]"[/red][purple]File/Spec/[blue]$module[/blue].pm[/purple][red]"[/red][red];[/red]
[blue]@ISA[/blue] = [red]([/red][red]"[/red][purple]File::Spec::[blue]$module[/blue][/purple][red]"[/red][red])[/red][red];[/red]

[fuchsia]1[/fuchsia][red];[/red]

[teal]__END__[/teal]
[tt]------------------------------------------------------------
Pragmas (perl 5.8.8) used :
[ul]
[li]strict - Perl pragma to restrict unsafe constructs[/li]
[li]vars - Perl pragma to predeclare global variable names (obsolete)[/li]
[/ul]
Core (perl 5.8.8) Modules used :
[ul]
[li]File::Spec - portably perform operations on file names[/li]
[/ul]
[/tt]

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top