develooper Front page | perl.perl5.porters | Postings from May 2002

Improved $^X patch

Thread Next
May 30, 2002 14:33
Improved $^X patch
Message ID:
OK, I have updated the definition of perlpath in
Porting/Glossary, added a new section to pod/perlport.pod about
the distinction between command names and file pathnames, and
made the initial changes suggested by Craig Berry to switch from
$Config{ext_ext} to $Config{_exe} and to fiddle the regular
expression to permit VMS version numbers at the end.

Craig, since you said you had a better regular expression
coming, please overwrite this initial version with your new
version when you submit your patch.

This does not address the issue of "see if this perl exists, if
not, use this other perl", but people should be able to reliably
code up such if-then-else algorithms from the information that
is presented here.  I don't think we need to get that specific
anyway, and I think that level of detail will vary from program
to program.

I hope this patch addresses everything except the exact VMS
suffix-avoidance regular expression.


diff -urp --new-file oldperl/Porting/Glossary newperl/Porting/Glossary
--- oldperl/Porting/Glossary	Thu May 30 15:36:34 2002
+++ newperl/Porting/Glossary	Thu May 30 17:17:54 2002
@@ -3603,7 +3603,13 @@ perllibs (End.U):
 perlpath (perlpath.U):
 	This variable contains the eventual value of the PERLPATH symbol,
 	which contains the name of the perl interpreter to be used in
-	shell scripts and in the "eval 'exec'" idiom.
+	shell scripts and in the "eval 'exec'" idiom.  This variable is
+	not necessarily the pathname of the file containing the perl
+	interpreter; you must append the executable extension (_exe) if
+	it is not already present.  Note that Perl code that runs during
+	the Perl build process cannot reference this variable, as Perl
+	may not have been installed, or even if installed, may be a
+	different version of Perl.
 pg (Loc.U):
 	This variable is used internally by Configure to determine the
diff -urp --new-file oldperl/pod/perlport.pod newperl/pod/perlport.pod
--- oldperl/pod/perlport.pod	Thu May 30 15:35:36 2002
+++ newperl/pod/perlport.pod	Thu May 30 15:35:47 2002
@@ -448,6 +448,36 @@ directories.
 Don't count on specific values of C<$!>.
+=head2 Command names versus file pathnames
+Don't assume that the name used to invoke a command or program with
+C<system> or C<exec> can also be used to test for the existence of the
+file that holds the executable code for that command or program.
+First, many operating systems have "internal" commands that are
+built-in to the OS and while these commands can be invoked, there is
+no corresponding file.  Second, some operating systems (Cygwin, DJGPP,
+OS/2, and VOS) have required suffixes for executable files; these
+suffixes are generally permitted on the command name but are not
+required.  Thus, a command like "perl" might exist in a file named
+"perl", "perl.exe", or "", depending on the operating system.
+The variable "_exe" in the Config module holds the executable suffix,
+if any.  Third, VMS files always end in a version number, which comes
+after the executable suffix.
+To convert $^X to a file pathname, taking account of the requirements
+of the various operating system possibilities, say:
+  use Config;
+  use File::Spec;
+  $thisperl = $^X;
+  $thisperl .= $Config{_exe} unless $thisperl ~= m/$Config{_exe}([;\d]*)$/i;
+To convert $Config{perlpath} to a file pathname, say:
+  use Config;
+  use File::Spec;
+  $thisperl = File::Spec->canonpath($Config{perlpath});
+  $thisperl .= $Config{_exe} unless $thisperl ~= m/$Config{_exe}([;\d]*)$/i;
 =head2 Interprocess Communication (IPC)
 In general, don't directly access the system in code meant to be
diff -urp --new-file oldperl/pod/perlvar.pod newperl/pod/perlvar.pod
--- oldperl/pod/perlvar.pod	Thu May 30 15:35:55 2002
+++ newperl/pod/perlvar.pod	Thu May 30 15:38:30 2002
@@ -1158,7 +1158,8 @@ a relative or absolute pathname of the p
 be the string used to invoke perl but not the pathname of the
 perl program file.  Also, most operating systems permit invoking
 programs that are not in the PATH environment variable, so there
-is no guarantee that the value of $^X is in PATH.
+is no guarantee that the value of $^X is in PATH.  For VMS, the
+value may or may not include a version number.
 You usually can use the value of $^X to re-invoke an independent
 copy of the same perl that is currently running, e.g.,
@@ -1179,8 +1180,8 @@ following statements:
   use Config;
   use File::Spec;
   $this_perl = File::Spec->canonpath($^X);
-  $this_perl .= $Config{exe_ext}
-          unless $this_perl =~ m/$Config{exe_ext}$/i;
+  $this_perl .= $Config{_ext}
+          unless $this_perl =~ m/$Config{_ext}([;\d]*)$/i;
 Because many operating systems permit anyone with read access to
 the Perl program file to make a copy of it, patch the copy, and
@@ -1193,8 +1194,8 @@ command or referenced as a file.
   use Config;
   use File::Spec;
   $secure_perl_path = File::Spec->canonpath($Config{perlpath});
-  $secure_perl_path .= $Config{exe_ext}
-          unless $secure_perl_path =~ m/$Config{exe_ext}$/i;
+  $secure_perl_path .= $Config{_ext}
+          unless $secure_perl_path =~ m/$Config{_ext}([;\d]*)$/i;
 =item ARGV
### END OF PATCH ###

Paul Green                  | Mail:
Senior Technical Consultant | Voice: +1 978-461-7557   FAX: +1 978-461-3610
Stratus Technologies        | Video: PictureTel/AT&T by request.
Maynard, MA  01754          | Disclaimer: I speak for myself, not Stratus.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About