Re: Backward compatibility: $^O in perl 4
by antirice (Priest) on May 07, 2003 at 14:45 UTC
|
A possible solution may be to look at $ENV{'OSTYPE'}. The variable is set by the shell on most Unix systems and as such should serve your purpose.
Please realize that $ENV{'OSTYPE'} doesn't necessarily always contain the OS as well as the version. As an example, a machine of mine running FreeBSD 4.7 with perl 5.8.0 prints the following:
> perl -e 'print $ENV{'OSTYPE'}," ",$^O,$/'
FreeBSD FreeBSD
>
This is my only machine that reports without the version, but just a head's up in case.
Update: Ah, this is wonderful:
> uname
FreeBSD
>
So perhaps $ENV{'OSTYPE'} is just as good as attempting to capture the output from uname.
antirice The first rule of Perl club is - use Perl The ith rule of Perl club is - follow rule i - 1 for i > 1 | [reply] [d/l] [select] |
|
|
| [reply] |
Re: Backward compatibility: $^O in perl 4
by Maddingue (Sexton) on May 07, 2003 at 15:15 UTC
|
Looking throught the Perl 4 documentation and library, I can't find anything that could help you. Using uname is indeed the simplest solution, but be careful that very few options of uname are common (or have the same meaning) upon the various Unix systems. I remember facing some troubles on HPUX and IRIX.
Probably a good start is to look at how autoconf or the Configure script from Perl do their system detection. | [reply] |
Re: Backward compatibility: $^O in perl 4
by krujos (Curate) on May 07, 2003 at 16:42 UTC
|
$OS_TYPE=`uname -s`
$OS_VERSION=`uname -r
Seems eaiser.
Update: This way there are no special cases needed in the code. | [reply] [d/l] |
|
|
bash$ uname -s
AIX
bash$ uname -r
3
bash$ uname -v
4
With your code the system will appear to have AIX 3 intead of 4...
Ciao! --bronto
The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz | [reply] [d/l] [select] |
|
|
Whoa. I have never caught that before, never had to worry about versions on AIX. Thanks, I will change my code accordingly. You Rock!
Josh
| [reply] |
Re: Backward compatibility: $^O in perl 4
by hawtin (Prior) on May 08, 2003 at 06:30 UTC
|
I had the same problem and came across a solution
that gcc uses. For various reasons this is
expressed as a bash script and a more recent
version is probably abailable. I leave the conversion
to Perl as an exercise for the reader:
# Short circuit this function if we know which system we are on
if [ $OS_SYSTEM_REALLY ]; then
echo "${OS_SYSTEM_REALLY}"
return
fi
# First get the values for this machine
# Code lifted from config.guess in the gcc software
OS_UNAME_M=`(uname -m) 2>/dev/null` || OS_UNAME_M=unknown
OS_UNAME_S=`(uname -s) 2>/dev/null` || OS_UNAME_S=unknown
OS_UNAME_R=`(uname -r) 2>/dev/null` || OS_UNAME_R=unknown
OS_UNAME_V=`(uname -v) 2>/dev/null` || OS_UNAME_V=unknown
OS_UNAME="${OS_UNAME_M}:${OS_UNAME_S}:${OS_UNAME_R}:${OS_UNAME_V}"
# Note: order is significant - the case branches are not exclusive
+.
case "${OS_UNAME}" in
sun4*:SunOS:5.[012345]*:*)
echo "sol24"
return ;;
sun4*:SunOS:5.[6789]*:*)
echo "sol26"
return ;;
sun4*:SunOS:[7891]*:*)
echo "Unknown Solaris version" >&2
echo "Try setting \$OS_SYSTEM_REALLY to sol26" >&2
echo "unknown"
return ;;
sun4*:SunOS:*:*)
echo "sun"
return ;;
*:AIX:1:4)
echo "aix41"
return ;;
*:IRIX*:5.*:*)
echo "sgi"
return ;;
*:IRIX*:6.[2345]:*)
echo "irix62"
return ;;
9000/[78]??:HP-UX:*:*)
echo "hp"
return ;;
i[345678]86:Linux:*:*)
echo "linux"
return ;;
sparc:Linux:*:*)
echo "ulinux"
return ;;
*:*:*:*)
# If we get here then we have something weird
echo "Unknown system \"${OS_UNAME}\"" >&2
echo "Try setting \$OS_SYSTEM_REALLY to one of sun, sol, h
+p etc" >&2
echo "unknown"
return ;;
esac
| [reply] [d/l] |
Re: Backward compatibility: $^O in perl 4
by dragonchild (Archbishop) on May 07, 2003 at 13:49 UTC
|
It's been a few hours since I used Perl4, but what is he doing that is system-dependent to the point that he needs to worry about uname?
------ We are the carpenters and bricklayers of the Information Age. Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement. Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified. | [reply] |
|
|
| [reply] |