New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perldoc(sort) bugs #16360
Comments
From jrw32982@gmail.comThis applies from perl 5.8 - 5.26 The perldoc(sort) documentation has long had bugs in it, relative to its The test program included below shows many of these effects. My sort @list_to_be_sorted Here are my comments on the specific text from perldoc(sort): #------------------------------------------------------------------------ @contact = sort { $a cmp $b } find_records @key; # ok If instead you want to sort the array @key with the comparison routine @contact = sort { find_records() } @key; # ok Here is my test program to demonstrate some of the weird results when using #!/usr/bin/perl use strict; use Test::More qw(no_plan); my @list = qw( c b e d ); sub g { return ( "a", @_ ) } # generate list #****************************************************************************** our @w; sub w { sub e { sub compile { like $^V, is_deeply [ sort @list ], $clist, " OK! sort L"; is_deeply [ sort { $a cmp $b } @list ], $clist, " OK! sort {<=>} L"; is_deeply [ sort( { $a cmp $b } @list) ], $clist, "OK! sort( {<=>} L)"; is_deeply [ sort ({ $a cmp $b } @list) ], $clist, "OK! sort ({<=>} L)"; is_deeply [ sort { $a cmp $b } g @list ], $glist, "OK! sort {<=>} g L"; is_deeply [ sort( { $a cmp $b } g @list) ], $glist, "OK! sort( {<=>} g L)"; is_deeply [ sort ({ $a cmp $b } g @list) ], $glist, "OK! sort ({<=>} g L)"; compile ' sort &g @list '; ok $@, " sort &g L @{[e]}"; compile ' sort( &g @list ) '; ok $@, " sort( &g L ) @{[e]}"; compile ' sort (&g @list ) '; ok $@, " sort (&g L ) @{[e]}"; is_deeply [ sort +g @list ], $glist, "OK! sort +g L"; is_deeply [ sort( +g @list ) ], $glist, "OK! sort( +g L )"; is_deeply [ sort (+g @list ) ], $glist, "OK! sort (+g L )"; is_deeply [ sort c @list ], $clist, "OK! sort c L"; is_deeply [ sort( c @list ) ], $clist, " sort( c L ) @{[w is_deeply [ sort (c @list ) ], $clist, " sort (c L ) @{[w is_deeply [ sort c g @list ], $glist, "OK! sort c g L"; is_deeply [ sort c +g @list ], $glist, "OK! sort c +g L"; is_deeply [ sort( c g @list )], $glist, " sort( c g L ) @{[w is_deeply [ sort (c g @list ) ], $glist, " sort (c g L ) @{[w my @nlist = ( 50, 51, 49 ); is_deeply [ sort map chr, @nlist ], $sslist, "OK! sort map mf, is_deeply [ sort( map chr, @nlist) ], $sslist, "ok sort( map mf, is_deeply [ sort ( map chr, @nlist) ], $sslist, "ok sort ( map mf, is $#w, $w-1, "warning_count"; # done_testing(); # not available in perl 5.8 #****************************************************************************** Perl Info
|
Migrated from rt.perl.org#132716 (status was 'new')
Searchable as RT132716$
The text was updated successfully, but these errors were encountered: