$^X
[p5sagit/p5-mst-13.2.git] / pod / perlvar.pod
index 2f31ea7..13922fe 100644 (file)
@@ -13,14 +13,20 @@ you need only say
 
     use English;
 
-at the top of your program.  This will alias all the short names to the
-long names in the current package.  Some even have medium names,
-generally borrowed from B<awk>.
+at the top of your program. This aliases all the short names to the long
+names in the current package. Some even have medium names, generally
+borrowed from B<awk>. In general, it's best to use the
 
-If you don't mind the performance hit, variables that depend on the
-currently selected filehandle may instead be set by calling an
-appropriate object method on the IO::Handle object.  (Summary lines
-below for this contain the word HANDLE.)  First you must say
+    use English '-no_match_vars';
+
+invocation if you don't need $PREMATCH, $MATCH, or $POSTMATCH, as it avoids
+a certain performance hit with the use of regular expressions. See
+L<English>.
+
+Variables that depend on the currently selected filehandle may be set by
+calling an appropriate object method on the IO::Handle object, although
+this is less efficient than using the regular built-in variables. (Summary
+lines below for this contain the word HANDLE.) First you must say
 
     use IO::Handle;
 
@@ -33,10 +39,11 @@ or more safely,
     HANDLE->method(EXPR)
 
 Each method returns the old value of the IO::Handle attribute.
-The methods each take an optional EXPR, which if supplied specifies the
+The methods each take an optional EXPR, which, if supplied, specifies the
 new value for the IO::Handle attribute in question.  If not supplied,
 most methods do nothing to the current value--except for
 autoflush(), which will assume a 1 for you, just to be different.
+
 Because loading in the IO::Handle class is an expensive operation, you should
 learn how to use the regular built-in variables.
 
@@ -209,7 +216,7 @@ BLOCK).  (Mnemonic: like & in some editors.)  This variable is read-only
 and dynamically scoped to the current BLOCK.
 
 The use of this variable anywhere in a program imposes a considerable
-performance penalty on all regular expression matches.  See L<BUGS>.
+performance penalty on all regular expression matches.  See L</BUGS>.
 
 =item $PREMATCH
 
@@ -221,7 +228,7 @@ enclosed by the current BLOCK).  (Mnemonic: C<`> often precedes a quoted
 string.)  This variable is read-only.
 
 The use of this variable anywhere in a program imposes a considerable
-performance penalty on all regular expression matches.  See L<BUGS>.
+performance penalty on all regular expression matches.  See L</BUGS>.
 
 =item $POSTMATCH
 
@@ -239,7 +246,7 @@ string.)  Example:
 This variable is read-only and dynamically scoped to the current BLOCK.
 
 The use of this variable anywhere in a program imposes a considerable
-performance penalty on all regular expression matches.  See L<BUGS>.
+performance penalty on all regular expression matches.  See L</BUGS>.
 
 =item $LAST_PAREN_MATCH
 
@@ -261,7 +268,7 @@ with the rightmost closing parenthesis) of the last successful search
 pattern.  (Mnemonic: the (possibly) Nested parenthesis that most
 recently closed.)
 
-This is primarly used inside C<(?{...})> blocks for examining text
+This is primarily used inside C<(?{...})> blocks for examining text
 recently matched. For example, to effectively capture text to a variable
 (in addition to C<$1>, C<$2>, etc.), replace C<(...)> with
 
@@ -331,7 +338,7 @@ of which filehandle C<$.> is currently aliased to.
 
 C<$.> is reset when the filehandle is closed, but B<not> when an open
 filehandle is reopened without an intervening close().  For more
-details, see L<perlop/"I/O Operators">.  Because C<< <> >> never does
+details, see L<perlop/"IE<sol>O Operators">.  Because C<< <> >> never does
 an explicit close, line numbers increase across ARGV files (but see
 examples in L<perlfunc/eof>).
 
@@ -656,8 +663,11 @@ Also see L<Error Indicators>.
 
 =item ${^ENCODING}
 
-The encoding used to interpret native eight-bit encodings to Unicode,
-see L<encode>.  An opaque C<Encode::XS> object.
+The I<object reference> to the Encode object that is used to convert
+the source code to Unicode.  Thanks to this variable your perl script
+does not have to be written in UTF-8.  Default is I<undef>.  The direct
+manipulation of this variable is highly discouraged.  See L<encoding>
+for more details.
 
 =item $OS_ERROR
 
@@ -666,9 +676,25 @@ see L<encode>.  An opaque C<Encode::XS> object.
 =item $!
 
 If used numerically, yields the current value of the C C<errno>
-variable, with all the usual caveats.  (This means that you shouldn't
-depend on the value of C<$!> to be anything in particular unless
-you've gotten a specific error return indicating a system error.)
+variable, or in other words, if a system or library call fails, it
+sets this variable.  This means that the value of C<$!> is meaningful
+only I<immediately> after a B<failure>:
+
+    if (open(FH, $filename)) {
+       # Here $! is meaningless.
+       ...
+    } else {
+       # ONLY here is $! meaningful.
+       ...
+       # Already here $! might be meaningless.
+    }
+    # Since here we might have either success or failure,
+    # here $! is meaningless.
+
+In the above I<meaningless> stands for anything: zero, non-zero,
+C<undef>.  A successful system or library call does B<not> set
+the variable to zero.
+
 If used an a string, yields the corresponding system error string.
 You can assign a number to C<$!> to set I<errno> if, for instance,
 you want C<"$!"> to return the string for error I<n>, or you want
@@ -677,6 +703,18 @@ went bang?)
 
 Also see L<Error Indicators>.
 
+=item %!
+
+Each element of C<%!> has a true value only if C<$!> is set to that
+value.  For example, C<$!{ENOENT}> is true if and only if the current
+value of C<$!> is C<ENOENT>; that is, if the most recent error was
+"No such file or directory" (or its moral equivalent: not all operating
+systems give that exact error, and certainly not all languages).
+To check if a particular key is meaningful on your system, use
+C<exists $!{the_key}>; for a list of legal keys, use C<keys %!>.
+See L<Errno> for more information, and also see above for the
+validity of C<$!>.
+
 =item $EXTENDED_OS_ERROR
 
 =item $^E
@@ -965,6 +1003,12 @@ built, as determined during the configuration process.  The value
 is identical to C<$Config{'osname'}>.  See also L<Config> and the 
 B<-V> command-line switch documented in L<perlrun>.
 
+=item ${^OPEN}
+
+An internal variable used by PerlIO.  A string in two parts, separated
+by a C<\0> byte, the first part is the input disciplines, the second
+part is the output disciplines.
+
 =item $PERLDB
 
 =item $^P
@@ -1064,6 +1108,11 @@ Control.)  Example:
 
     warn "No \"our\" declarations!\n" if $^V and $^V lt v5.6.0;
 
+To convert C<$^V> into its string representation use sprintf()'s
+C<"%vd"> conversion:
+
+    printf "version is v%vd\n", $^V;  # Perl's version
+
 See the documentation of C<use VERSION> and C<require VERSION>
 for a convenient way to fail if the running Perl interpreter is too old.
 
@@ -1101,8 +1150,22 @@ lexical scope.  See L<bytes>.
 
 =item $^X
 
-The name that the Perl binary itself was executed as, from C's C<argv[0]>.
-This may not be a full pathname, nor even necessarily in your path.
+The name that the Perl binary itself was executed as, from C's
+C<argv[0]>.
+
+This may not be a full pathname, nor even necessarily in your
+path. Currently there is no universal solution for this, you may try
+to use:
+
+  use Config;
+  $current_perl_path = (-x $^X) ? $^X : $Config{perlpath};
+
+The security-conscious would write:
+
+  use Config;
+  use File::Spec;
+  $current_perl_path = (File::Spec->file_name_is_absolute($^X) && -x $^X)
+                     ? $^X : $Config{perlpath};
 
 =item ARGV
 
@@ -1140,7 +1203,8 @@ C<require>, or C<use> constructs look for their library files.  It
 initially consists of the arguments to any B<-I> command-line
 switches, followed by the default Perl library, probably
 F</usr/local/lib/perl>, followed by ".", to represent the current
-directory.  If you need to modify this at runtime, you should use
+directory.  ("." will not be appended if taint checks are enabled, either by
+C<-T> or by C<-t>.)  If you need to modify this at runtime, you should use
 the C<use lib> pragma to get the machine-dependent library properly
 loaded also:
 
@@ -1381,7 +1445,7 @@ expression matches in a program, regardless of whether they occur
 in the scope of C<use English>.  For that reason, saying C<use
 English> in libraries is strongly discouraged.  See the
 Devel::SawAmpersand module documentation from CPAN
-(http://www.cpan.org/modules/by-module/Devel/)
+( http://www.cpan.org/modules/by-module/Devel/ )
 for more information.
 
 Having to even think about the C<$^S> variable in your exception