Perl::...tBlock(3pm)
π NAME π
okay so bestie, this is the Perl::...tBlock(3pm) page from the User Contributed Perl Documentation, and it's all about Perl::Critic::Policy::BuiltinFunctions::ProhibitReverseSortBlock β aka the policy that says: Forbid $b before $a in sort blocks. periodt π
π¦ AFFILIATION π¦
This Policy is part of the core Perl::Critic distribution. It's literally built in, no cap. π«Ά
β¨ DESCRIPTION β¨
Conway says it's much clearer to use reverse than to flip $a and $b around inside a sort block. He also suggests that, in newer perls, reverse is specifically looked for and optimized, and in the case of a simple reversed string sort, using reverse with a sort with no block is faster even in old perls. the way that's lowkey iconic β¨
Here's the vibe check β these are not ok vs ok:
my @foo = sort { $b cmp $a } @bar; #not ok
my @foo = reverse sort @bar; #ok
my @foo = sort { $b <=> $a } @bar; #not ok
my @foo = reverse sort { $a <=> $b } @bar; #ok
π CONFIGURATION π
This Policy is not configurable except for the standard options. That's it β no extra knobs, no secret settings. π
πΈ AUTHOR πΈ
Chris Dolan <cdolan@cpan.org> β yes, that's the author credit, bestie. πΈ
π COPYRIGHT π
Copyright (c) 2006-2011 Chris Dolan.
The license tea: This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π
Source/version + date, for the record: perl v5.42.0, dated 2024-10-23. Bye bestie, go make your sort blocks cute and correct πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Perl-Critic 1.156.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms