X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlop.pod;h=40ea2c8e9ccdb2b15b3418b8a48fd1c9e38a50b5;hb=7360c6b444ea6e19b6583f9530f845bee19c7921;hp=378a74c1922af283f176e24e9c31321f34bd054e;hpb=be25f60935927114e0ef411fb4fbc04fea5ce8fa;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlop.pod b/pod/perlop.pod index 378a74c..40ea2c8 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -602,10 +602,10 @@ Examples: As a scalar operator: if (101 .. 200) { print; } # print 2nd hundred lines, short for - # if ($. == 101 .. $. == 200) ... + # if ($. == 101 .. $. == 200) { print; } next LINE if (1 .. /^$/); # skip header lines, short for - # ... if ($. == 1 .. /^$/); + # next LINE if ($. == 1 .. /^$/); # (typically in a loop labeled LINE) s/^/> / if (/^$/ .. eof()); # quote body @@ -615,9 +615,9 @@ As a scalar operator: $in_header = 1 .. /^$/; $in_body = /^$/ .. eof; if ($in_header) { - # ... + # do something } else { # in body - # ... + # do something else } } continue { close ARGV if eof; # reset $. each file @@ -783,10 +783,17 @@ In list context, it's just the list argument separator, and inserts both its arguments into the list. These arguments are also evaluated from left to right. -The C<< => >> operator is a synonym for the comma, but forces any word -(consisting entirely of word characters) to its left to be interpreted -as a string (as of 5.001). This includes words that might otherwise be -considered a constant or function call. +The C<< => >> operator is a synonym for the comma except that it causes +its left operand to be interpreted as a string if it begins with a letter +or underscore and is composed only of letters, digits and underscores. +This includes operands that might otherwise be interpreted as operators, +constants, single number v-strings or function calls. If in doubt about +this behaviour, the left operand can be quoted explicitly. + +Otherwise, the C<< => >> operator behaves exactly as the comma operator +or list argument separator, according to context. + +For example: use constant FOO => "something"; @@ -800,23 +807,17 @@ It is I: my %h = ("something", 23); -If the argument on the left is not a word, it is first interpreted as -an expression, and then the string value of that is used. - The C<< => >> operator is helpful in documenting the correspondence between keys and values in hashes, and other paired elements in lists. %hash = ( $key => $value ); login( $username => $password ); -=head2 Yada Yada Operators -X<...> X<... operator> X X X X -X +=head2 Yada Yada Operator +X<...> X<... operator> X -The yada yada operators are placeholders for code. They parse without error, -but when executed either throw an exception or a warning. - -The C<...> operator takes no arguments. When executed, it throws an exception +The yada yada operator (noted C<...>) is a placeholder for code. +It parses without error, but when executed it throws an exception with the text C: sub foo { ... } @@ -824,23 +825,7 @@ with the text C: Unimplemented at line . -The C operator is similar, but it takes one argument, a string to use as -the text of the exception: - - sub bar { !!! "Don't call me, Ishmael!" } - bar(); - - Don't call me, Ishmael! at line . - -The C operator also takes one argument, but it emits a warning instead of -throwing an exception: - - sub baz { ??? "Who are you? Wnat do you want?" } - baz(); - say "Why are you here?"; - - Who are you? What do you want? at line . - Why are you here? +It takes no argument. =head2 List Operators (Rightward) X X @@ -1167,11 +1152,13 @@ process modifiers are available: c Do not reset search position on a failed match when /g is in effect. If "/" is the delimiter then the initial C is optional. With the C -you can use any pair of non-alphanumeric, non-whitespace characters +you can use any pair of non-whitespace characters as delimiters. This is particularly useful for matching path names that contain "/", to avoid LTS (leaning toothpick syndrome). If "?" is the delimiter, then the match-only-once rule of C applies. If "'" is the delimiter, no interpolation is performed on the PATTERN. +When using a character valid in an identifier, whitespace is required +after the C. PATTERN may contain variables, which will be interpolated (and the pattern recompiled) every time the pattern search is evaluated, except @@ -1309,7 +1296,7 @@ doing different actions depending on which regexp matched. Each regexp tries to match where the previous one leaves off. $_ = <<'EOL'; - $url = URI::URL->new( "http://www/" ); die if $url eq "xXx"; + $url = URI::URL->new( "http://example.com/" ); die if $url eq "xXx"; EOL LOOP: { @@ -1381,13 +1368,13 @@ specific options: e Evaluate the right side as an expression. ee Evaluate the right side as a string then eval the result -Any non-alphanumeric, non-whitespace delimiter may replace the -slashes. If single quotes are used, no interpretation is done on the -replacement string (the C modifier overrides this, however). Unlike -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., +Any non-whitespace delimiter may replace the slashes. Add space after +the C when using a character allowed in identifiers. If single quotes +are used, no interpretation is done on the replacement string (the C +modifier overrides this, however). Unlike 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 or C<< s/bar/ >>. A C will cause the replacement portion to be treated as a full-fledged Perl expression and evaluated right then and there. It is, however, syntax checked at @@ -2196,7 +2183,7 @@ to terminate the loop, they should be tested for explicitly: while (($_ = ) ne '0') { ... } while () { last unless $_; ... } -In other boolean contexts, C<< > >> without an +In other boolean contexts, IfilehandleE>> without an explicit C test or comparison elicit a warning if the C pragma or the B<-w> command-line switch (the C<$^W> variable) is in effect. @@ -2246,6 +2233,18 @@ internally--<> is just a synonym for , which is magical. (The pseudo code above doesn't work because it treats as non-magical.) +Since the null filehandle uses the two argument form of L +it interprets special characters, so if you have a script like this: + + while (<>) { + print; + } + +and call it with C, it actually opens a +pipe, executes the C command and reads C's output from that pipe. +If you want all items in C<@ARGV> to be interpreted as file names, you +can use the module C from CPAN. + 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