X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlvar.pod;h=13922fecd85d7e5cae21b7c7ad8a60fb44fd3dd9;hb=38e4f4aed799ac2e3ef36186e997df88f9da92d2;hp=6f9bd8d3a684048e020024b9df7b6d392fb80e11;hpb=9ae8cd5b44680cc8af3d7ecc507f22e5e2031731;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlvar.pod b/pod/perlvar.pod index 6f9bd8d..13922fe 100644 --- a/pod/perlvar.pod +++ b/pod/perlvar.pod @@ -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. +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. 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. + +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. +performance penalty on all regular expression matches. See L. =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. +performance penalty on all regular expression matches. See L. =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. +performance penalty on all regular expression matches. See L. =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 when an open filehandle is reopened without an intervening close(). For more -details, see L. Because C<< <> >> never does +details, see LO Operators">. Because C<< <> >> never does an explicit close, line numbers increase across ARGV files (but see examples in L). @@ -654,6 +661,14 @@ status; see L for details. Also see L. +=item ${^ENCODING} + +The I 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. The direct +manipulation of this variable is highly discouraged. See L +for more details. + =item $OS_ERROR =item $ERRNO @@ -661,9 +676,25 @@ Also see L. =item $! If used numerically, yields the current value of the C C -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 after a B: + + 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 stands for anything: zero, non-zero, +C. A successful system or library call does B 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 if, for instance, you want C<"$!"> to return the string for error I, or you want @@ -672,6 +703,18 @@ went bang?) Also see L. +=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; 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; for a list of legal keys, use C. +See L for more information, and also see above for the +validity of C<$!>. + =item $EXTENDED_OS_ERROR =item $^E @@ -844,10 +887,9 @@ of perl in the right bracket?) Example: See also the documentation of C and C for a convenient way to fail if the running Perl interpreter is too old. -The use of this variable is deprecated. The floating point representation -can sometimes lead to inaccurate numeric comparisons. See C<$^V> for a -more modern representation of the Perl version that allows accurate string -comparisons. +The floating point representation can sometimes lead to inaccurate +numeric comparisons. See C<$^V> for a more modern representation of +the Perl version that allows accurate string comparisons. =item $COMPILING @@ -961,6 +1003,12 @@ built, as determined during the configuration process. The value is identical to C<$Config{'osname'}>. See also L and the B<-V> command-line switch documented in L. +=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 @@ -1039,6 +1087,11 @@ The time at which the program began running, in seconds since the epoch (beginning of 1970). The values returned by the B<-M>, B<-A>, and B<-C> filetests are based on this value. +=item ${^TAINT} + +Reflects if taint mode is on or off (i.e. if the program was run with +B<-T> or not). True for on, false for off. + =item $PERL_VERSION =item $^V @@ -1055,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 and C for a convenient way to fail if the running Perl interpreter is too old. @@ -1092,8 +1150,22 @@ lexical scope. See L. =item $^X -The name that the Perl binary itself was executed as, from C's C. -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. + +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 @@ -1131,7 +1203,8 @@ C, or C 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, 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 pragma to get the machine-dependent library properly loaded also: @@ -1372,7 +1445,7 @@ expression matches in a program, regardless of whether they occur in the scope of C. For that reason, saying C in libraries is strongly discouraged. See the Devel::SawAmpersand module documentation from CPAN -(http://www.perl.com/CPAN/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