"$Bill Luebkert" <[EMAIL PROTECTED]> writes:

> Works fine for me:
> 
> if ($^O =~ /win32/i) {
>       print "we are in win32\n";
> } elsif ($^O =~ /linux/i) {
>       print "we are in linux\n";
> }

I recommend:

    if ($^O eq "MSWin32") {
        print "we are in win32\n";
    }
    elsif ($^O eq "linux") {
        print "we are in linux\n";
    }

No need to use fuzzy regular expressions to match fixed strings.

Some people prefer this scheme instead:

    use strict;
    use constant IS_WIN32 $^O eq "MSWin32";
    use constant IS_LINUX $^O eq "linux";

    if (IS_WIN32)   {
        print "we are in win32\n";
    }
    elsif (IS_LINUX) {
        print "we are in linux\n";
    }

The advantage here is that perl will catch misspellings for you and
that perl will completely eliminate the code that does not apply
during its compilation phase.  In the former code snippets the $^O
expressions end up evaluated each time execution pass through that
code.

Regards,
Gisle
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to