Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.94k stars 554 forks source link

[PATCH] perlop.pod: 1. Remove trailing space. 2. Convert "\t"s to spaces #14665

Closed p5pRT closed 7 years ago

p5pRT commented 9 years ago

Migrated from rt.perl.org#124359 (status was 'resolved')

Searchable as RT124359$

p5pRT commented 9 years ago

From @shlomif

The first patch removes trailing space from perlop.pod while the second one convert "\t"s to spaces ("\x20") globally there.

Please consider applying them.

These commits can also be found here​:

https://github.com/shlomif/perl/tree/shlomif-perlop-tabs-and-spaces-cleanup

I hereby disclaim any implicit or explicit copyright ownership on these changes and place them under your choice of Public Domain/CC-Zero/MIT-X11-licence/Same-terms-as-Perl/Artistic 2.0/Any other licence.

Regards\,

  Shlomi Fish

--


Shlomi Fish http​://www.shlomifish.org/ http​://is.gd/htwEXQ - Integrating GNU Guile into GNU coreutils

The American Lottery​: all you need is a dollar and a dream. We will take the dollar\, but you can keep the dream.

Please reply to list if it's a mailing list post - http​://shlom.in/reply .

p5pRT commented 9 years ago

From @shlomif

0001-perlop-Remove-trailing-whitespace.patch ```diff From b0103af6be9eebc1449ae30e8f2f144ed61e5e11 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Tue, 21 Apr 2015 16:02:42 +0300 Subject: [PATCH 1/2] [perlop] Remove trailing whitespace. This is as a precursor to the next commit in which I'll convert all "\t"s there to spaces. --- pod/perlop.pod | 86 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/pod/perlop.pod b/pod/perlop.pod index 3c364c1..26a4748 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -392,7 +392,7 @@ If you get tired of being subject to your platform's native integers, the S> pragma neatly sidesteps the issue altogether: print 20 << 20; # 20971520 - print 20 << 40; # 5120 on 32-bit machines, + print 20 << 40; # 5120 on 32-bit machines, # 21990232555520 on 64-bit machines use bigint; print 20 << 100; # 25353012004564588029934064107520 @@ -437,7 +437,7 @@ See also L<"Terms and List Operators (Leftward)">. =head2 Relational Operators X X -Perl operators that return true or false generally return values +Perl operators that return true or false generally return values that can be safely used as numbers. For example, the relational operators in this section and the equality operators in the next one return C<1> for true and a special version of the defined empty @@ -567,81 +567,81 @@ whose types apply determines the smartmatch behavior. Because what actually happens is mostly determined by the type of the second operand, the table is sorted on the right operand instead of on the left. - Left Right Description and pseudocode + Left Right Description and pseudocode =============================================================== - Any undef check whether Any is undefined + Any undef check whether Any is undefined like: !defined Any Any Object invoke ~~ overloading on Object, or die Right operand is an ARRAY: - Left Right Description and pseudocode + Left Right Description and pseudocode =============================================================== ARRAY1 ARRAY2 recurse on paired elements of ARRAY1 and ARRAY2[2] like: (ARRAY1[0] ~~ ARRAY2[0]) && (ARRAY1[1] ~~ ARRAY2[1]) && ... - HASH ARRAY any ARRAY elements exist as HASH keys + HASH ARRAY any ARRAY elements exist as HASH keys like: grep { exists HASH->{$_} } ARRAY Regexp ARRAY any ARRAY elements pattern match Regexp like: grep { /Regexp/ } ARRAY - undef ARRAY undef in ARRAY + undef ARRAY undef in ARRAY like: grep { !defined } ARRAY - Any ARRAY smartmatch each ARRAY element[3] + Any ARRAY smartmatch each ARRAY element[3] like: grep { Any ~~ $_ } ARRAY Right operand is a HASH: - Left Right Description and pseudocode + Left Right Description and pseudocode =============================================================== - HASH1 HASH2 all same keys in both HASHes + HASH1 HASH2 all same keys in both HASHes like: keys HASH1 == grep { exists HASH2->{$_} } keys HASH1 - ARRAY HASH any ARRAY elements exist as HASH keys + ARRAY HASH any ARRAY elements exist as HASH keys like: grep { exists HASH->{$_} } ARRAY - Regexp HASH any HASH keys pattern match Regexp + Regexp HASH any HASH keys pattern match Regexp like: grep { /Regexp/ } keys HASH - undef HASH always false (undef can't be a key) + undef HASH always false (undef can't be a key) like: 0 == 1 - Any HASH HASH key existence + Any HASH HASH key existence like: exists HASH->{Any} Right operand is CODE: - Left Right Description and pseudocode + Left Right Description and pseudocode =============================================================== ARRAY CODE sub returns true on all ARRAY elements[1] like: !grep { !CODE->($_) } ARRAY HASH CODE sub returns true on all HASH keys[1] like: !grep { !CODE->($_) } keys HASH - Any CODE sub passed Any returns true + Any CODE sub passed Any returns true like: CODE->(Any) Right operand is a Regexp: - Left Right Description and pseudocode + Left Right Description and pseudocode =============================================================== - ARRAY Regexp any ARRAY elements match Regexp + ARRAY Regexp any ARRAY elements match Regexp like: grep { /Regexp/ } ARRAY - HASH Regexp any HASH keys match Regexp + HASH Regexp any HASH keys match Regexp like: grep { /Regexp/ } keys HASH - Any Regexp pattern match + Any Regexp pattern match like: Any =~ /Regexp/ Other: - Left Right Description and pseudocode + Left Right Description and pseudocode =============================================================== Object Any invoke ~~ overloading on Object, or fall back to... - Any Num numeric equality + Any Num numeric equality like: Any == Num Num nummy[4] numeric equality like: Num == nummy undef Any check whether undefined like: !defined(Any) - Any Any string equality + Any Any string equality like: Any eq Any @@ -650,13 +650,13 @@ Notes: =over =item 1. -Empty hashes or arrays match. +Empty hashes or arrays match. =item 2. That is, each element smartmatches the element of the same index in the other array.[3] =item 3. -If a circular reference is found, fall back to referential equality. +If a circular reference is found, fall back to referential equality. =item 4. Either an actual number, or a string that looks like one. @@ -711,7 +711,7 @@ recursively. my @bigger = ("red", "blue", [ "orange", "green" ] ); if (@little ~~ @bigger) { # true! say "little is contained in bigger"; - } + } Because the smartmatch operator recurses on nested arrays, this will still report that "red" is in the array. @@ -725,21 +725,21 @@ If two arrays smartmatch each other, then they are deep copies of each others' values, as this example reports: use v5.12.0; - my @a = (0, 1, 2, [3, [4, 5], 6], 7); - my @b = (0, 1, 2, [3, [4, 5], 6], 7); + my @a = (0, 1, 2, [3, [4, 5], 6], 7); + my @b = (0, 1, 2, [3, [4, 5], 6], 7); if (@a ~~ @b && @b ~~ @a) { say "a and b are deep copies of each other"; - } + } elsif (@a ~~ @b) { say "a smartmatches in b"; - } + } elsif (@b ~~ @a) { say "b smartmatches in a"; - } + } else { say "a and b don't smartmatch each other at all"; - } + } If you were to set S>, then instead of reporting that "a and b @@ -814,7 +814,7 @@ C>, overloading may or may not be invoked. For simple strings or numbers, "in" becomes equivalent to this: $object ~~ $number ref($object) == $number - $object ~~ $string ref($object) eq $string + $object ~~ $string ref($object) eq $string For example, this reports that the handle smells IOish (but please don't really do this!): @@ -823,7 +823,7 @@ For example, this reports that the handle smells IOish my $fh = IO::Handle->new(); if ($fh ~~ /\bIO\b/) { say "handle smells IOish"; - } + } That's because it treats C<$fh> as a string like C<"IO::Handle=GLOB(0x8039e0)">, then pattern matches against that. @@ -936,7 +936,7 @@ It would be even more readable to write that this way: unless(unlink("alpha", "beta", "gamma")) { gripe(); next LINE; - } + } Using C<"or"> for assignment is unlikely to do what you want; see below. @@ -1082,9 +1082,9 @@ To get the 25 traditional lowercase Greek letters, including both sigmas, you could use this instead: use charnames "greek"; - my @greek_small = map { chr } ( ord("\N{alpha}") + my @greek_small = map { chr } ( ord("\N{alpha}") .. - ord("\N{omega}") + ord("\N{omega}") ); However, because there are I other lowercase Greek characters than @@ -1677,7 +1677,7 @@ is done. Returns a Perl value which may be used instead of the corresponding C/msixpodualn> expression. The returned value is a normalized version of the original pattern. It magically differs from a string containing the same characters: C returns "Regexp"; -however, dereferencing it is not well defined (you currently get the +however, dereferencing it is not well defined (you currently get the normalized version of the original pattern, but this may change). @@ -1855,7 +1855,7 @@ If the C option is not used, C in list context returns a list consisting of the subexpressions matched by the parentheses in the pattern, that is, (C<$1>, C<$2>, C<$3>...) (Note that here C<$1> etc. are also set). When there are no parentheses in the pattern, the return -value is the list C<(1)> for success. +value is the list C<(1)> for success. With or without parentheses, an empty list is returned upon failure. Examples: @@ -2275,7 +2275,7 @@ On some platforms (notably DOS-like ones), the shell may not be capable of dealing with multiline commands, so putting newlines in the string may not get you what you want. You may be able to evaluate multiple commands in a single line by separating them with the command -separator character, if your shell supports that (for example, C<;> on +separator character, if your shell supports that (for example, C<;> on many Unix shells and C<&> on the Windows NT C shell). Perl will attempt to flush all files opened for @@ -2670,7 +2670,7 @@ If the left part is delimited by bracketing punctuation (that is C<()>, C<[]>, C<{}>, or C<< <> >>), the right part needs another pair of delimiters such as C and C. In these cases, whitespace and comments are allowed between the two parts, although the comment must follow -at least one whitespace character; otherwise a character expected as the +at least one whitespace character; otherwise a character expected as the start of the comment may be regarded as the starting delimiter of the right part. During this search no attention is paid to the semantics of the construct. @@ -2957,7 +2957,7 @@ The following lines are equivalent: print while ($_ = ); print while ; -This also behaves similarly, but assigns to a lexical variable +This also behaves similarly, but assigns to a lexical variable instead of to C<$_>: while (my $line = ) { print $line } @@ -3164,7 +3164,7 @@ variable substitution. Backslash interpolation also happens at compile time. You can say 'Now is the time for all' - . "\n" + . "\n" . 'good men to come to.' and this all reduces to one string internally. Likewise, if -- 2.3.2 ```
p5pRT commented 9 years ago

From @shlomif

0002-perlop-convert-t-to-spaces.patch ```diff From 2fb8e6d0b31932557009b22e8734bd628d49aa1a Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Tue, 21 Apr 2015 16:13:56 +0300 Subject: [PATCH 2/2] perlop: convert "\t" to spaces. This is for consistency and for accurate display. This was done by using the following Vim commands: :set ts=8 :retab --- pod/perlop.pod | 378 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 189 insertions(+), 189 deletions(-) diff --git a/pod/perlop.pod b/pod/perlop.pod index 26a4748..ebdbdf0 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -46,30 +46,30 @@ C's precedence is slightly screwy. (This makes learning Perl easier for C folks.) With very few exceptions, these all operate on scalar values only, not array values. - left terms and list operators (leftward) - left -> - nonassoc ++ -- - right ** - right ! ~ \ and unary + and - - left =~ !~ - left * / % x - left + - . - left << >> - nonassoc named unary operators - nonassoc < > <= >= lt gt le ge - nonassoc == != <=> eq ne cmp ~~ - left & - left | ^ - left && - left || // - nonassoc .. ... - right ?: - right = += -= *= etc. goto last next redo dump - left , => - nonassoc list operators (rightward) - right not - left and - left or xor + left terms and list operators (leftward) + left -> + nonassoc ++ -- + right ** + right ! ~ \ and unary + and - + left =~ !~ + left * / % x + left + - . + left << >> + nonassoc named unary operators + nonassoc < > <= >= lt gt le ge + nonassoc == != <=> eq ne cmp ~~ + left & + left | ^ + left && + left || // + nonassoc .. ... + right ?: + right = += -= *= etc. goto last next redo dump + left , => + nonassoc list operators (rightward) + right not + left and + left or xor In the following sections, these operators are covered in precedence order. @@ -96,7 +96,7 @@ whether you are looking at the left side or the right side of the operator. For example, in @ary = (1, 3, sort 4, 2); - print @ary; # prints 1324 + print @ary; # prints 1324 the commas on the right of the C are evaluated before the C, but the commas on the left are evaluated after. In other words, @@ -105,13 +105,13 @@ then act like a simple TERM with regard to the preceding expression. Be careful with parentheses: # These evaluate exit before doing the print: - print($foo, exit); # Obviously not what you want. - print $foo, exit; # Nor is this. + print($foo, exit); # Obviously not what you want. + print $foo, exit; # Nor is this. # These do the print before evaluating exit: - (print $foo), exit; # This is what you want. - print($foo), exit; # Or this. - print ($foo), exit; # Or even this. + (print $foo), exit; # This is what you want. + print($foo), exit; # Or this. + print ($foo), exit; # Or even this. Also note that @@ -188,10 +188,10 @@ has a value that is not the empty string and matches the pattern C, the increment is done as a string, preserving each character within its range, with carry: - print ++($foo = "99"); # prints "100" - print ++($foo = "a0"); # prints "a1" - print ++($foo = "Az"); # prints "Ba" - print ++($foo = "zz"); # prints "aaa" + print ++($foo = "99"); # prints "100" + print ++($foo = "a0"); # prints "a1" + print ++($foo = "Az"); # prints "Ba" + print ++($foo = "zz"); # prints "aaa" C is always treated as numeric, and in particular is changed to C<0> before incrementing (so that a post-increment of an undef value @@ -342,12 +342,12 @@ negative), it returns an empty string or an empty list, depending on the context. X - print '-' x 80; # print row of dashes + print '-' x 80; # print row of dashes - print "\t" x ($tab/8), ' ' x ($tab%8); # tab over + print "\t" x ($tab/8), ' ' x ($tab%8); # tab over - @ones = (1) x 80; # a list of 80 1's - @ones = (5) x @ones; # set all elements to 5 + @ones = (1) x 80; # a list of 80 1's + @ones = (5) x @ones; # set all elements to 5 =head2 Additive Operators @@ -409,22 +409,22 @@ arguments within parentheses are taken to be of highest precedence, just like a normal function call. For example, because named unary operators are higher precedence than C<||>: - chdir $foo || die; # (chdir $foo) || die - chdir($foo) || die; # (chdir $foo) || die - chdir ($foo) || die; # (chdir $foo) || die - chdir +($foo) || die; # (chdir $foo) || die + chdir $foo || die; # (chdir $foo) || die + chdir($foo) || die; # (chdir $foo) || die + chdir ($foo) || die; # (chdir $foo) || die + chdir +($foo) || die; # (chdir $foo) || die but, because C<"*"> is higher precedence than named operators: - chdir $foo * 20; # chdir ($foo * 20) - chdir($foo) * 20; # (chdir $foo) * 20 - chdir ($foo) * 20; # (chdir $foo) * 20 - chdir +($foo) * 20; # chdir ($foo * 20) + chdir $foo * 20; # chdir ($foo * 20) + chdir($foo) * 20; # (chdir $foo) * 20 + chdir ($foo) * 20; # (chdir $foo) * 20 + chdir +($foo) * 20; # chdir ($foo * 20) - rand 10 * 20; # rand (10 * 20) - rand(10) * 20; # (rand 10) * 20 - rand (10) * 20; # (rand 10) * 20 - rand +(10) * 20; # rand (10 * 20) + rand 10 * 20; # rand (10 * 20) + rand(10) * 20; # (rand 10) * 20 + rand (10) * 20; # (rand 10) * 20 + rand +(10) * 20; # rand (10 * 20) Regarding precedence, the filetest operators, like C<-f>, C<-M>, etc. are treated like named unary operators, but they don't follow this functional @@ -906,16 +906,16 @@ The C<||>, C and C<&&> operators return the last value evaluated portable way to find out the home directory might be: $home = $ENV{HOME} - // $ENV{LOGDIR} - // (getpwuid($<))[7] - // die "You're homeless!\n"; + // $ENV{LOGDIR} + // (getpwuid($<))[7] + // die "You're homeless!\n"; In particular, this means that you shouldn't use this for selecting between two aggregates for assignment: - @a = @b || @c; # this is wrong - @a = scalar(@b) || @c; # really meant this - @a = @b ? @b : @c; # this works fine, though + @a = @b || @c; # this is wrong + @a = scalar(@b) || @c; # really meant this + @a = @b ? @b : @c; # this works fine, though As alternatives to C<&&> and C<||> when used for control flow, Perl provides the C and C operators (see below). @@ -924,12 +924,12 @@ and C<"or"> is much lower, however, so that you can safely use them after a list operator without the need for parentheses: unlink "alpha", "beta", "gamma" - or gripe(), next LINE; + or gripe(), next LINE; With the C-style operators that would have been written like this: unlink("alpha", "beta", "gamma") - || (gripe(), next LINE); + || (gripe(), next LINE); It would be even more readable to write that this way: @@ -955,7 +955,7 @@ versions of Perl might burn a lot of memory when you write something like this: for (1 .. 1_000_000) { - # code + # code } The range operator also works on strings, using the magical @@ -1107,7 +1107,7 @@ argument before the C<:> is returned, otherwise the argument after the C<:> is returned. For example: printf "I have %d dog%s.\n", $n, - ($n == 1) ? "" : "s"; + ($n == 1) ? "" : "s"; Scalar or list context propagates downward into the 2nd or 3rd argument, whichever is selected. @@ -1294,7 +1294,7 @@ Binary C<"or"> returns the logical disjunction of the two surrounding expressions. It's equivalent to C<||> except for the very low precedence. This makes it useful for control flow: - print FH $data or die "Can't write to FH: $!"; + print FH $data or die "Can't write to FH: $!"; This means that it short-circuits: the right expression is evaluated only if the left expression is false. Due to its precedence, you must @@ -1354,19 +1354,19 @@ for these behaviors, but also provides a way for you to choose your quote character for any of them. In the following table, a C<{}> represents any pair of delimiters you choose. - Customary Generic Meaning Interpolates - '' q{} Literal no - "" qq{} Literal yes - `` qx{} Command yes* - qw{} Word list no - // m{} Pattern match yes* - qr{} Pattern yes* - s{}{} Substitution yes* - tr{}{} Transliteration no (but see below) - y{}{} Transliteration no (but see below) + Customary Generic Meaning Interpolates + '' q{} Literal no + "" qq{} Literal yes + `` qx{} Command yes* + qw{} Word list no + // m{} Pattern match yes* + qr{} Pattern yes* + s{}{} Substitution yes* + tr{}{} Transliteration no (but see below) + y{}{} Transliteration no (but see below) < X<\u> X<\L> X<\U> X<\E> X<\Q> X<\F> - \l lowercase next character only - \u titlecase (not uppercase!) next character only - \L lowercase all characters till \E or end of string - \U uppercase all characters till \E or end of string - \F foldcase all characters till \E or end of string + \l lowercase next character only + \u titlecase (not uppercase!) next character only + \L lowercase all characters till \E or end of string + \U uppercase all characters till \E or end of string + \F foldcase all characters till \E or end of string \Q quote (disable) pattern metacharacters till \E or end of string - \E end either case modification or quoted section - (whichever was last seen) + \E end either case modification or quoted section + (whichever was last seen) See L for the exact definition of characters that are quoted by C<\Q>. @@ -1694,25 +1694,25 @@ is equivalent to The result may be used as a subpattern in a match: $re = qr/$pattern/; - $string =~ /foo${re}bar/; # can be interpolated in other + $string =~ /foo${re}bar/; # can be interpolated in other # patterns - $string =~ $re; # or used standalone - $string =~ /$re/; # or this way + $string =~ $re; # or used standalone + $string =~ /$re/; # or this way Since Perl may compile the pattern at the moment of execution of the C operator, using C may have speed advantages in some situations, notably if the result of C is used standalone: sub match { - my $patterns = shift; - my @compiled = map qr/$_/i, @$patterns; - grep { - my $success = 0; - foreach my $pat (@compiled) { - $success = 1, last if /$pat/; - } - $success; - } @_; + my $patterns = shift; + my @compiled = map qr/$_/i, @$patterns; + grep { + my $success = 0; + foreach my $pat (@compiled) { + $success = 1, last if /$pat/; + } + $success; + } @_; } Precompilation of the pattern into an internal representation at @@ -1723,15 +1723,15 @@ we did not use C operator.) Options (specified by the following modifiers) are: - m Treat string as multiple lines. - s Treat string as single line. (Make . match a newline) - i Do case-insensitive pattern matching. - x Use extended regular expressions. - p When matching preserve a copy of the matched string so + m Treat string as multiple lines. + s Treat string as single line. (Make . match a newline) + i Do case-insensitive pattern matching. + x Use extended regular expressions. + p When matching preserve a copy of the matched string so that ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH} will be defined (ignored starting in v5.20) as these are always defined starting in that relese - o Compile pattern only once. + o Compile pattern only once. a ASCII-restrict: Use ASCII for \d, \s, \w; specifying two a's further restricts things to that that no ASCII character will match a non-ASCII one under /i. @@ -1863,7 +1863,7 @@ Examples: open(TTY, "+ =~ /^y/i && foo(); # do foo if desired + =~ /^y/i && foo(); # do foo if desired if (/Version: *([0-9.]*)/) { $version = $1; } @@ -1919,9 +1919,9 @@ Examples: # scalar context local $/ = ""; while ($paragraph = <>) { - while ($paragraph =~ /\p{Ll}['")]*[.!?]+['")]*\s/g) { - $sentences++; - } + while ($paragraph =~ /\p{Ll}['")]*[.!?]+['")]*\s/g) { + $sentences++; + } } say $sentences; @@ -2025,11 +2025,11 @@ something in each file of a set of files, for instance. Only C patterns local to the current package are reset. while (<>) { - if (m?^$?) { - # blank line between header and body - } + if (m?^$?) { + # blank line between header and body + } } continue { - reset if eof; # clear m?? status for next file + reset if eof; # clear m?? status for next file } Another example switched the first "latin1" encoding it finds @@ -2078,7 +2078,7 @@ expression is used instead. See L for further explanation on these. Options are as with C with the addition of the following replacement specific options: - e Evaluate the right side as an expression. + e Evaluate the right side as an expression. ee Evaluate the right side as a string then eval the result. r Return substitution and leave the original string @@ -2099,33 +2099,33 @@ to be Ced before being run as a Perl expression. Examples: - s/\bgreen\b/mauve/g; # don't change wintergreen + s/\bgreen\b/mauve/g; # don't change wintergreen $path =~ s|/usr/bin|/usr/local/bin|; s/Login: $foo/Login: $bar/; # run-time pattern - ($foo = $bar) =~ s/this/that/; # copy first, then + ($foo = $bar) =~ s/this/that/; # copy first, then # change - ($foo = "$bar") =~ s/this/that/; # convert to string, + ($foo = "$bar") =~ s/this/that/; # convert to string, # copy, then change - $foo = $bar =~ s/this/that/r; # Same as above using /r + $foo = $bar =~ s/this/that/r; # Same as above using /r $foo = $bar =~ s/this/that/r - =~ s/that/the other/r; # Chained substitutes + =~ s/that/the other/r; # Chained substitutes # using /r - @foo = map { s/this/that/r } @bar # /r is very useful in + @foo = map { s/this/that/r } @bar # /r is very useful in # maps $count = ($paragraph =~ s/Mister\b/Mr./g); # get change-cnt $_ = 'abc123xyz'; - s/\d+/$&*2/e; # yields 'abc246xyz' - s/\d+/sprintf("%5d",$&)/e; # yields 'abc 246xyz' - s/\w/$& x 2/eg; # yields 'aabbcc 224466xxyyzz' + s/\d+/$&*2/e; # yields 'abc246xyz' + s/\d+/sprintf("%5d",$&)/e; # yields 'abc 246xyz' + s/\w/$& x 2/eg; # yields 'aabbcc 224466xxyyzz' - s/%(.)/$percent{$1}/g; # change percent escapes; no /e - s/%(.)/$percent{$1} || $&/ge; # expr now, so /e - s/^=(\w+)/pod($1)/ge; # use function call + s/%(.)/$percent{$1}/g; # change percent escapes; no /e + s/%(.)/$percent{$1} || $&/ge; # expr now, so /e + s/^=(\w+)/pod($1)/ge; # use function call $_ = 'abc123xyz'; $x = s/abc/def/r; # $x is 'def123xyz' and @@ -2148,21 +2148,21 @@ Examples: # Delete (most) C comments. $program =~ s { - /\* # Match the opening delimiter. - .*? # Match a minimal number of characters. - \*/ # Match the closing delimiter. + /\* # Match the opening delimiter. + .*? # Match a minimal number of characters. + \*/ # Match the closing delimiter. } []gsx; - s/^\s*(.*?)\s*$/$1/; # trim whitespace in $_, + s/^\s*(.*?)\s*$/$1/; # trim whitespace in $_, # expensively - for ($variable) { # trim whitespace in $variable, + for ($variable) { # trim whitespace in $variable, # cheap - s/^\s+//; - s/\s+$//; + s/^\s+//; + s/\s+$//; } - s/([^ ]*) *([^ ]*)/$2 $1/; # reverse 1st two fields + s/([^ ]*) *([^ ]*)/$2 $1/; # reverse 1st two fields Note the use of C<$> instead of C<\> in the last example. Unlike B, we use the \> form only in the left hand side. @@ -2195,7 +2195,7 @@ the delimiter or backslash is interpolated. $foo = q!I said, "You said, 'She said it.'"!; $bar = q('This is it.'); - $baz = '\n'; # a two-character string + $baz = '\n'; # a two-character string =item C/> X X X<"> X<""> @@ -2206,8 +2206,8 @@ A double-quoted, interpolated string. $_ .= qq (*** The previous line contains the naughty word "$1".\n) - if /\b(tcl|java|python)\b/i; # :-) - $baz = "\n"; # a one-character string + if /\b(tcl|java|python)\b/i; # :-) + $baz = "\n"; # a one-character string =item C/> X X<`> X<``> X @@ -2385,11 +2385,11 @@ character sets in full. Options: - c Complement the SEARCHLIST. - d Delete found but unreplaced characters. - s Squash duplicate replaced characters. - r Return the modified string and leave the original string - untouched. + c Complement the SEARCHLIST. + d Delete found but unreplaced characters. + s Squash duplicate replaced characters. + r Return the modified string and leave the original string + untouched. If the C modifier is specified, the I character set is complemented. If the C modifier is specified, any characters @@ -2409,15 +2409,15 @@ squashing character sequences in a class. Examples: - $ARGV[1] =~ tr/A-Z/a-z/; # canonicalize to lower case ASCII + $ARGV[1] =~ tr/A-Z/a-z/; # canonicalize to lower case ASCII - $cnt = tr/*/*/; # count the stars in $_ + $cnt = tr/*/*/; # count the stars in $_ - $cnt = $sky =~ tr/*/*/; # count the stars in $sky + $cnt = $sky =~ tr/*/*/; # count the stars in $sky - $cnt = tr/0-9//; # count the digits in $_ + $cnt = tr/0-9//; # count the digits in $_ - tr/a-zA-Z//s; # bookkeeper -> bokeper + tr/a-zA-Z//s; # bookkeeper -> bokeper ($HOST = $host) =~ tr/a-z/A-Z/; $HOST = $host =~ tr/a-z/A-Z/r; # same thing @@ -2425,13 +2425,13 @@ Examples: $HOST = $host =~ tr/a-z/A-Z/r # chained with s///r =~ s/:/ -p/r; - tr/a-zA-Z/ /cs; # change non-alphas to single space + tr/a-zA-Z/ /cs; # change non-alphas to single space @stripped = map tr/a-zA-Z/ /csr, @original; - # /r with map + # /r with map tr [\200-\377] - [\000-\177]; # wickedly delete 8th bit + [\000-\177]; # wickedly delete 8th bit If multiple transliterations are given for a character, only the first one is used: @@ -2496,11 +2496,11 @@ other quoting construct. Just as in the shell, a backslashed bareword following the C<<< << >>> means the same thing as a single-quoted string does: - $cost = <<'VISTA'; # hasta la ... + $cost = <<'VISTA'; # hasta la ... That'll be $10 please, ma'am. VISTA - $cost = <<\VISTA; # Same thing! + $cost = <<\VISTA; # Same thing! That'll be $10 please, ma'am. VISTA @@ -2681,7 +2681,7 @@ Thus: or: m/ - bar # NOT a comment, this slash / terminated m//! + bar # NOT a comment, this slash / terminated m//! /x do not form legal quoted expressions. The quoted part ends on the @@ -3004,17 +3004,17 @@ gives you standard input. The C<@ARGV> array is then processed as a list of filenames. The loop while (<>) { - ... # code for each line + ... # code for each line } is equivalent to the following Perl-like pseudo code: unshift(@ARGV, '-') unless @ARGV; while ($ARGV = shift) { - open(ARGV, $ARGV); - while () { - ... # code for each line - } + open(ARGV, $ARGV); + while () { + ... # code for each line + } } except that it isn't so cumbersome to say, and will actually work. @@ -3065,15 +3065,15 @@ If you want to pass switches into your script, you can use one of the C modules or put a loop on the front like this: while ($_ = $ARGV[0], /^-/) { - shift; + shift; last if /^--$/; - if (/^-D(.*)/) { $debug = $1 } - if (/^-v/) { $verbose++ } - # ... # other switches + if (/^-D(.*)/) { $debug = $1 } + if (/^-v/) { $verbose++ } + # ... # other switches } while (<>) { - # ... # code for each line + # ... # code for each line } The C<< <> >> symbol will return C for end-of-file only once. @@ -3108,15 +3108,15 @@ internal function directly as C, which is probably the right way to have done it in the first place.) For example: while (<*.c>) { - chmod 0644, $_; + chmod 0644, $_; } is roughly equivalent to: open(FOO, "echo *.c | tr -s ' \t\r\f' '\\012\\012\\012\\012'|"); while () { - chomp; - chmod 0644, $_; + chomp; + chmod 0644, $_; } except that the globbing is actually done internally using the standard @@ -3171,7 +3171,7 @@ and this all reduces to one string internally. Likewise, if you say foreach $file (@filenames) { - if (-s $file > 5 + 100 * 2**16) { } + if (-s $file > 5 + 100 * 2**16) { } } the compiler precomputes the number which that expression @@ -3200,23 +3200,23 @@ The granularity for such extension or truncation is one or more bytes. # ASCII-based examples - print "j p \n" ^ " a h"; # prints "JAPH\n" - print "JA" | " ph\n"; # prints "japh\n" - print "japh\nJunk" & '_____'; # prints "JAPH\n"; - print 'p N$' ^ " E bitwise operation. You may explicitly show which type of operation you intend by using C<""> or C<0+>, as in the examples below. - $foo = 150 | 105; # yields 255 (0x96 | 0x69 is 0xFF) - $foo = '150' | 105; # yields 255 - $foo = 150 | '105'; # yields 255 - $foo = '150' | '105'; # yields string '155' (under ASCII) + $foo = 150 | 105; # yields 255 (0x96 | 0x69 is 0xFF) + $foo = '150' | 105; # yields 255 + $foo = 150 | '105'; # yields 255 + $foo = '150' | '105'; # yields string '155' (under ASCII) - $baz = 0+$foo & 0+$bar; # both ops explicitly numeric - $biz = "$foo" ^ "$bar"; # both ops explicitly stringy + $baz = 0+$foo & 0+$bar; # both ops explicitly numeric + $biz = "$foo" ^ "$bar"; # both ops explicitly stringy This somewhat unpredictable behavior can be avoided with the experimental "bitwise" feature, new in Perl 5.22. You can enable it via S) forces it to treat its operands as strings: use experimental "bitwise"; - $foo = 150 | 105; # yields 255 (0x96 | 0x69 is 0xFF) - $foo = '150' | 105; # yields 255 - $foo = 150 | '105'; # yields 255 - $foo = '150' | '105'; # yields 255 - $foo = 150 |. 105; # yields string '155' (under ASCII) - $foo = '150' |. 105; # yields string '155' - $foo = 150 |.'105'; # yields string '155' - $foo = '150' |.'105'; # yields string '155' - - $baz = $foo & $bar; # both operands numeric - $biz = $foo ^. $bar; # both operands stringy + $foo = 150 | 105; # yields 255 (0x96 | 0x69 is 0xFF) + $foo = '150' | 105; # yields 255 + $foo = 150 | '105'; # yields 255 + $foo = '150' | '105'; # yields 255 + $foo = 150 |. 105; # yields string '155' (under ASCII) + $foo = '150' |. 105; # yields string '155' + $foo = 150 |.'105'; # yields string '155' + $foo = '150' |.'105'; # yields string '155' + + $baz = $foo & $bar; # both operands numeric + $biz = $foo ^. $bar; # both operands stringy The assignment variants of these operators (C<&= |= ^= &.= |.= ^.=>) behave likewise under the feature. @@ -3299,11 +3299,11 @@ decimal places. See Knuth, volume II, for a more robust treatment of this topic. sub fp_equal { - my ($X, $Y, $POINTS) = @_; - my ($tX, $tY); - $tX = sprintf("%.${POINTS}g", $X); - $tY = sprintf("%.${POINTS}g", $Y); - return $tX eq $tY; + my ($X, $Y, $POINTS) = @_; + my ($tX, $tY); + $tX = sprintf("%.${POINTS}g", $X); + $tY = sprintf("%.${POINTS}g", $Y); + return $tX eq $tY; } The POSIX module (part of the standard perl distribution) implements @@ -3330,10 +3330,10 @@ they're currently pretty slow. At the cost of some space and considerable speed, they avoid the normal pitfalls associated with limited-precision representations. - use 5.010; - use bigint; # easy interface to Math::BigInt - $x = 123456789123456789; - say $x * $x; + use 5.010; + use bigint; # easy interface to Math::BigInt + $x = 123456789123456789; + say $x * $x; +15241578780673678515622620750190521 Or with rationals: -- 2.3.2 ```
p5pRT commented 7 years ago

From @jkeenan

On Tue\, 21 Apr 2015 13​:25​:27 GMT\, shlomif@​shlomifish.org wrote​:

The first patch removes trailing space from perlop.pod while the second one convert "\t"s to spaces ("\x20") globally there.

Please consider applying them.

These commits can also be found here​:

https://github.com/shlomif/perl/tree/shlomif-perlop-tabs-and-spaces- cleanup

Since I know that cleaning up trailing whitespace is less controversial than changing tabs to spaces (though I'd vote for that myself)\, I'm going to apply the first patch\, but not the second\, and then mark the ticket Resolved.

Pushed to blead in commit a727cfacf4b7894de3ae8c4b906a3bffccd751be.

Thank you very much. -- James E Keenan (jkeenan@​cpan.org)

p5pRT commented 7 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 7 years ago

@jkeenan - Status changed from 'open' to 'resolved'