[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] A small routine



I just thought I'd post a small MacPerl routine for CGI
writers.  It determines what OS you are running under and
returns the properly pathnamed file string.

#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#
#	Proper Path
#	A program by Mark Manning
#
#	Permission is granted to copy, modify, throw away, and
#	otherwise mangle this routine as you see fit.  You probably
#	would have written this yourself if you hadn't seen this
#	thing first.  :-)  Have fun!
#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#
sub pp
{
	local( $theFile ) = @_;

	local( $theDirectory );
#
#	Get the current pathname.
#
	$theDirectory = `pwd`;
#
#	Remove the \r from the end of the string.
#
	chop( $theDirectory );
#
#	Determine the OS we are under.
#
#	If it is a Macintosh OS then the PWD will have colons in it.  So just add
#	a colon between the directory and the filename.  If it is an IBM OS, then
#	the PWD will have backslashes in it.  So add one of those between the
#	directory and the filename.  Otherwise we assume the OS is a Unix variant
#	and put in the forwards slash.  As a precaution against something really
#	bad happening in Perl - we also provide a return statement with a minus
#	one as the return.
#
	if( $^O =~ /MacOS/i ){
		return( "$theDirectory:$theFile" );
		}
		elsif( $^O =~ /IBM/i ){
			return( "$theDirectory\\$theFile" );
			}
		else{
			return( "$theDirectory/$theFile" );
			}
#
#	Else return an error
#
	return( -1 );
}