clarify docs on return value from binding operators
[p5sagit/p5-mst-13.2.git] / pod / perlop.pod
index 6e65ba3..5e4ce93 100644 (file)
@@ -95,7 +95,7 @@ as well as L<"I/O Operators">.
 
 =head2 The Arrow Operator
 
-"C<-E<gt>>" is an infix dereference operator, just as it is in C
+"C<< -> >>" is an infix dereference operator, just as it is in C
 and C++.  If the right side is either a C<[...]>, C<{...}>, or a
 C<(...)> subscript, then the left side must be either a hard or
 symbolic reference to an array, a hash, or a subroutine respectively.
@@ -148,9 +148,12 @@ starts with a plus or minus, a string starting with the opposite sign
 is returned.  One effect of these rules is that C<-bareword> is equivalent
 to C<"-bareword">.
 
-Unary "~" performs bitwise negation, i.e., 1's complement.  For example,
-C<0666 &~ 027> is 0640.  (See also L<Integer Arithmetic> and L<Bitwise
-String Operators>.)
+Unary "~" performs bitwise negation, i.e., 1's complement.  For
+example, C<0666 & ~027> is 0640.  (See also L<Integer Arithmetic> and
+L<Bitwise String Operators>.)  Note that the width of the result is
+platform-dependent: ~0 is 32 bits wide on a 32-bit platform, but 64
+bits wide on a 64-bit platform, so if you are expecting a certain bit
+width, remember use the & operator to mask off the excess bits.
 
 Unary "+" has no effect whatsoever, even on strings.  It is useful
 syntactically for separating a function name from a parenthesized expression
@@ -169,11 +172,14 @@ search or modify the string $_ by default.  This operator makes that kind
 of operation work on some other string.  The right argument is a search
 pattern, substitution, or transliteration.  The left argument is what is
 supposed to be searched, substituted, or transliterated instead of the default
-$_.  The return value indicates the success of the operation.  (If the
-right argument is an expression rather than a search pattern,
+$_.  When used in scalar context, the return value generally indicates the
+success of the operation.  Behavior in list context depends on the particular
+operator.  See L</"Regexp Quote-Like Operators"> for details.
+
+If the right argument is an expression rather than a search pattern,
 substitution, or transliteration, it is interpreted as a search pattern at run
-time.  This can be is less efficient than an explicit search, because the
-pattern must be compiled every time the expression is evaluated).
+time.  This can be less efficient than an explicit search, because the
+pattern must be compiled every time the expression is evaluated.
 
 Binary "!~" is just like "=~" except the return value is negated in
 the logical sense.
@@ -259,16 +265,16 @@ See also L<"Terms and List Operators (Leftward)">.
 
 =head2 Relational Operators
 
-Binary "E<lt>" returns true if the left argument is numerically less than
+Binary "<" returns true if the left argument is numerically less than
 the right argument.
 
-Binary "E<gt>" returns true if the left argument is numerically greater
+Binary ">" returns true if the left argument is numerically greater
 than the right argument.
 
-Binary "E<lt>=" returns true if the left argument is numerically less than
+Binary "<=" returns true if the left argument is numerically less than
 or equal to the right argument.
 
-Binary "E<gt>=" returns true if the left argument is numerically greater
+Binary ">=" returns true if the left argument is numerically greater
 than or equal to the right argument.
 
 Binary "lt" returns true if the left argument is stringwise less than
@@ -291,7 +297,7 @@ the right argument.
 Binary "!=" returns true if the left argument is numerically not equal
 to the right argument.
 
-Binary "E<lt>=E<gt>" returns -1, 0, or 1 depending on whether the left
+Binary "<=>" returns -1, 0, or 1 depending on whether the left
 argument is numerically less than, equal to, or greater than the right
 argument.
 
@@ -362,7 +368,7 @@ With the C-style operators that would have been written like this:
     unlink("alpha", "beta", "gamma")
            || (gripe(), next LINE);
 
-Use "or" for assignment is unlikely to do what you want; see below.
+Using "or" for assignment is unlikely to do what you want; see below.
 
 =head2 Range Operators
 
@@ -541,7 +547,7 @@ argument and returns that value.  This is just like C's comma operator.
 In list context, it's just the list argument separator, and inserts
 both its arguments into the list.
 
-The =E<gt> digraph is mostly just a synonym for the comma operator.  It's useful for
+The => digraph is mostly just a synonym for the comma operator.  It's useful for
 documenting arguments that come in pairs.  As of release 5.001, it also forces
 any word to the left of it to be interpreted as a string.
 
@@ -643,7 +649,7 @@ sorts of brackets (round, angle, square, curly) will all nest, which means
 that 
 
        q{foo{bar}baz} 
-       
+
 is the same as 
 
        'foo{bar}baz'
@@ -789,7 +795,7 @@ the trailing delimiter.  This avoids expensive run-time recompilations,
 and is useful when the value you are interpolating won't change over
 the life of the script.  However, mentioning C</o> constitutes a promise
 that you won't change the variables in the pattern.  If you change them,
-Perl won't even notice.  See also L<qr//>.
+Perl won't even notice.  See also L<"qr//">.
 
 If the PATTERN evaluates to the empty string, the last
 I<successfully> matched regular expression is used instead.
@@ -963,7 +969,7 @@ notably if the result of qr() is used standalone:
        my @compiled = map qr/$_/i, @$patterns;
        grep {
            my $success = 0;
-           foreach my $pat @compiled {
+           foreach my $pat (@compiled) {
                $success = 1, last if /$pat/;
            }
            $success;
@@ -1074,9 +1080,9 @@ this expression:
 
     qw(foo bar baz)
 
-is exactly equivalent to the list:
+is semantically equivalent to the list:
 
-    ('foo', 'bar', 'baz')
+    'foo', 'bar', 'baz'
 
 Some frequently seen examples:
 
@@ -1127,7 +1133,7 @@ Perl 4, Perl 5 treats backticks as normal delimiters; the replacement
 text is not evaluated as a command.  If the
 PATTERN is delimited by bracketing quotes, the REPLACEMENT has its own
 pair of quotes, which may or may not be bracketing quotes, e.g.,
-C<s(foo)(bar)> or C<sE<lt>fooE<gt>/bar/>.  A C</e> will cause the
+C<s(foo)(bar)> or C<< s<foo>/bar/ >>.  A C</e> will cause the
 replacement portion to be interpreted as a full-fledged Perl expression
 and eval()ed right then and there.  It is, however, syntax checked at
 compile-time.
@@ -1178,8 +1184,8 @@ Examples:
     s/([^ ]*) *([^ ]*)/$2 $1/; # reverse 1st two fields
 
 Note the use of $ instead of \ in the last example.  Unlike
-B<sed>, we use the \E<lt>I<digit>E<gt> form in only the left hand side.
-Anywhere else it's $E<lt>I<digit>E<gt>.
+B<sed>, we use the \<I<digit>> form in only the left hand side.
+Anywhere else it's $<I<digit>>.
 
 Occasionally, you can't use just a C</g> to get all the changes
 to occur that you might want.  Here are two common cases:
@@ -1317,8 +1323,8 @@ one to five, but these passes are always performed in the same order.
 The first pass is finding the end of the quoted construct, whether
 it be a multicharacter delimiter C<"\nEOF\n"> in the C<<<EOF>
 construct, a C</> that terminates a C<qq//> construct, a C<]> which
-terminates C<qq[]> construct, or a C<E<gt>> which terminates a
-fileglob started with C<E<lt>>.
+terminates C<qq[]> construct, or a C<< > >> which terminates a
+fileglob started with C<< < >>.
 
 When searching for single-character non-pairing delimiters, such
 as C</>, combinations of C<\\> and C<\/> are skipped.  However,
@@ -1374,7 +1380,7 @@ No interpolation is performed.
 
 The only interpolation is removal of C<\> from pairs C<\\>.
 
-=item C<"">, C<``>, C<qq//>, C<qx//>, C<<file*globE<gt>>
+=item C<"">, C<``>, C<qq//>, C<qx//>, C<< <file*glob> >>
 
 C<\Q>, C<\U>, C<\u>, C<\L>, C<\l> (possibly paired with C<\E>) are
 converted to corresponding Perl constructs.  Thus, C<"$foo\Qbaz$bar">
@@ -1409,7 +1415,7 @@ scalar.
 
 Note also that the interpolation code needs to make a decision on
 where the interpolated scalar ends.  For instance, whether 
-C<"a $b -E<gt> {c}"> really means:
+C<< "a $b -> {c}" >> really means:
 
   "a " . $b . " -> {c}";
 
@@ -1584,7 +1590,7 @@ to terminate the loop, they should be tested for explicitly:
     while (($_ = <STDIN>) ne '0') { ... }
     while (<STDIN>) { last unless $_; ... }
 
-In other boolean contexts, C<E<lt>I<filehandle>E<gt>> without an
+In other boolean contexts, C<< <I<filehandle>> >> without an
 explicit C<defined> test or comparison elicit a warning if the B<-w>
 command-line switch (the C<$^W> variable) is in effect.
 
@@ -1595,18 +1601,18 @@ rather than global.)  Additional filehandles may be created with
 the open() function, amongst others.  See L<perlopentut> and
 L<perlfunc/open> for details on this.
 
-If a E<lt>FILEHANDLEE<gt> is used in a context that is looking for
+If a <FILEHANDLE> is used in a context that is looking for
 a list, a list comprising all input lines is returned, one line per
 list element.  It's easy to grow to a rather large data space this
 way, so use with care.
 
-E<lt>FILEHANDLEE<gt> may also be spelled C<readline(*FILEHANDLE)>.
+<FILEHANDLE> may also be spelled C<readline(*FILEHANDLE)>.
 See L<perlfunc/readline>.
 
-The null filehandle E<lt>E<gt> is special: it can be used to emulate the
-behavior of B<sed> and B<awk>.  Input from E<lt>E<gt> comes either from
+The null filehandle <> is special: it can be used to emulate the
+behavior of B<sed> and B<awk>.  Input from <> comes either from
 standard input, or from each file listed on the command line.  Here's
-how it works: the first time E<lt>E<gt> is evaluated, the @ARGV array is
+how it works: the first time <> is evaluated, the @ARGV array is
 checked, and if it is empty, C<$ARGV[0]> is set to "-", which when opened
 gives you standard input.  The @ARGV array is then processed as a list
 of filenames.  The loop
@@ -1628,11 +1634,11 @@ is equivalent to the following Perl-like pseudo code:
 except that it isn't so cumbersome to say, and will actually work.
 It really does shift the @ARGV array and put the current filename
 into the $ARGV variable.  It also uses filehandle I<ARGV>
-internally--E<lt>E<gt> is just a synonym for E<lt>ARGVE<gt>, which
+internally--<> is just a synonym for <ARGV>, which
 is magical.  (The pseudo code above doesn't work because it treats
-E<lt>ARGVE<gt> as non-magical.)
+<ARGV> as non-magical.)
 
-You can modify @ARGV before the first E<lt>E<gt> as long as the array ends up
+You can modify @ARGV before the first <> as long as the array ends up
 containing the list of filenames you really want.  Line numbers (C<$.>)
 continue as though the input were one big happy file.  See the example
 in L<perlfunc/eof> for how to reset line numbers on each file.
@@ -1662,12 +1668,12 @@ Getopts modules or put a loop on the front like this:
        # ...           # code for each line
     }
 
-The E<lt>E<gt> symbol will return C<undef> for end-of-file only once.  
+The <> symbol will return C<undef> for end-of-file only once.  
 If you call it again after this, it will assume you are processing another 
 @ARGV list, and if you haven't set @ARGV, will read input from STDIN.
 
 If angle brackets contain is a simple scalar variable (e.g.,
-E<lt>$fooE<gt>), then that variable contains the name of the
+<$foo>), then that variable contains the name of the
 filehandle to input from, or its typeglob, or a reference to the
 same.  For example:
 
@@ -1679,16 +1685,16 @@ scalar variable containing a filehandle name, typeglob, or typeglob
 reference, it is interpreted as a filename pattern to be globbed, and
 either a list of filenames or the next filename in the list is returned,
 depending on context.  This distinction is determined on syntactic
-grounds alone.  That means C<E<lt>$xE<gt>> is always a readline() from
-an indirect handle, but C<E<lt>$hash{key}E<gt>> is always a glob().
+grounds alone.  That means C<< <$x> >> is always a readline() from
+an indirect handle, but C<< <$hash{key}> >> is always a glob().
 That's because $x is a simple scalar variable, but C<$hash{key}> is
 not--it's a hash element.
 
 One level of double-quote interpretation is done first, but you can't
-say C<E<lt>$fooE<gt>> because that's an indirect filehandle as explained
+say C<< <$foo> >> because that's an indirect filehandle as explained
 in the previous paragraph.  (In older versions of Perl, programmers
 would insert curly brackets to force interpretation as a filename glob:
-C<E<lt>${foo}E<gt>>.  These days, it's considered cleaner to call the
+C<< <${foo}> >>.  These days, it's considered cleaner to call the
 internal function directly as C<glob($foo)>, which is probably the right
 way to have done it in the first place.)  For example:
 
@@ -1696,7 +1702,7 @@ way to have done it in the first place.)  For example:
        chmod 0644, $_;
     }
 
-is equivalent to
+is roughly equivalent to:
 
     open(FOO, "echo *.c | tr -s ' \t\r\f' '\\012\\012\\012\\012'|");
     while (<FOO>) {
@@ -1704,20 +1710,11 @@ is equivalent to
        chmod 0644, $_;
     }
 
-In fact, it's currently implemented that way, but this is expected
-to be made completely internal in the near future.  (Which means
-it will not work on filenames with spaces in them unless you have
-csh(1) on your machine.)  Of course, the shortest way to do the
-above is:
+except that the globbing is actually done internally using the standard
+C<File::Glob> extension.  Of course, the shortest way to do the above is:
 
     chmod 0644, <*.c>;
 
-Because globbing currently invokes a shell, it's often faster to
-call readdir() yourself and do your own grep() on the filenames.
-Furthermore, due to its current implementation of using a shell,
-the glob() routine may get "Arg list too long" errors (unless you've
-installed tcsh(1L) as F</bin/csh> or hacked your F<config.sh>).
-
 A (file)glob evaluates its (embedded) argument only when it is
 starting a new list.  All values must be read before it will start
 over.  In list context, this isn't important because you automatically
@@ -1889,3 +1886,5 @@ limited-precision representations.
 The non-standard modules SSLeay::BN and Math::Pari provide
 equivalent functionality (and much more) with a substantial
 performance savings.
+
+=cut