In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/475b224feea308464e18cc6bef788e7a152afa51?hp=1f74a12bfce8b82144fa7fef29618af1e8023298>
- Log ----------------------------------------------------------------- commit 475b224feea308464e18cc6bef788e7a152afa51 Author: James E Keenan <jkee...@cpan.org> Date: Thu Jan 26 22:44:03 2017 -0500 Correct file mode and line lengths to keep porting tests happy. ----------------------------------------------------------------------- Summary of changes: pod/perlfunc.pod | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) mode change 100755 => 100644 pod/perlfunc.pod diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod old mode 100755 new mode 100644 index 6294b5d65f..2b962aa9a3 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -7322,22 +7322,37 @@ name of the variables in the sort block : package main; my $a = "C"; # DANGER, Will Robinson, DANGER !!! - print sort { $a cmp $b } qw(A C E G B D F H); # WRONG + print sort { $a cmp $b } qw(A C E G B D F H); + # WRONG sub badlexi { $a cmp $b } - print sort badlexi qw(A C E G B D F H); # WRONG - # the above print BACFEDGH or some other incorrect ordering - - print sort { $::a cmp $::b } qw(A C E G B D F H); # OK - print sort { our $a cmp our $b } qw(A C E G B D F H); # also OK - print sort { our ($a, $b); $a cmp $b } qw(A C E G B D F H); # also OK + print sort badlexi qw(A C E G B D F H); + # WRONG + # the above prints BACFEDGH or some other incorrect ordering + + print sort { $::a cmp $::b } qw(A C E G B D F H); + # OK + print sort { our $a cmp our $b } qw(A C E G B D F H); + # also OK + print sort { our ($a, $b); $a cmp $b } qw(A C E G B D F H); + # also OK sub lexi { our $a cmp our $b } - print sort lexi qw(A C E G B D F H); # also OK + print sort lexi qw(A C E G B D F H); + # also OK # the above print ABCDEFGH With proper care you may mix package and my (or state) C<$a> and/or C<$b>: - my $a = { tiny => -2, small => -1, normal => 0, big => 1, huge => 2 }; - say sort { $a->{our $a} <=> $a->{our $b} } qw{ huge normal tiny small big}; + my $a = { + tiny => -2, + small => -1, + normal => 0, + big => 1, + huge => 2 + }; + + say sort { $a->{our $a} <=> $a->{our $b} } + qw{ huge normal tiny small big}; + # prints tinysmallnormalbighuge C<$a> and C<$b> are implicitely local to the sort() execution and regain their -- Perl5 Master Repository