[sf-perl] perlstyle

Miller Hall miller.hall at gmail.com
Thu Jul 15 14:33:29 PDT 2021


num in that context is a subroutine meant as a shortcut for numerical
sorting.

The more full example is the following

#!/usr/bin/env perl

use strict;
use warnings;

sub num {
    $a <=> $b;
}

my %array = ( a => 1, b => 2, c => 3 );

sub foo { return print reverse sort num values %array }

foo();


You can read about this in the spec for sort
https://perldoc.perl.org/functions/sort

- Miller

On Thu, Jul 15, 2021 at 1:48 PM David Christensen <dpchrist at holgerdanske.com>
wrote:

> San Francisco Perl Mongers:
>
> Regarding the "perlstyle" document [1]:
>
> 1.  Under "Regarding aesthetics of code lay out ...", "Space after last
> parenthesis matching on current line" would seem to only make sense when
> additional code follows a closing parenthesis.  E.g.
>
>         if ( ... ) {
>             ...
>         }
>
>      And:
>
>         my $x = foo( ... ) && ... ;
>
>      But not:
>
>         my $z = bar( ... );
>
> 2.  Under "Along the same lines, just because you CAN omit parentheses
> ...", what is "num" in the example code?
>
>         return print reverse sort num values %array;
>
>      My Perl says:
>
>         2021-07-15 13:19:07 dpchrist at dipsy ~/sandbox/perl
>         $ cat /etc/debian_version ; uname -a ; perl -v | head -n 2 | tail
> -n 1
>         10.10
>         Linux dipsy 4.19.0-17-amd64 #1 SMP Debian 4.19.194-2 (2021-06-21)
> x86_64 GNU/Linux
>         This is perl 5, version 28, subversion 1 (v5.28.1) built for
> x86_64-linux-gnu-thread-multi
>
>         2021-07-15 13:19:11 dpchrist at dipsy ~/sandbox/perl
>         $ cat perlstyle-num.pl
>         #!/usr/bin/env perl
>         use strict;
>         use warnings;
>
>         my %array = ( a => 1, b => 2, c => 3 );
>
>         sub foo { return print reverse sort num values %array }
>
>         foo();
>
>         2021-07-15 13:19:25 dpchrist at dipsy ~/sandbox/perl
>         $ perl perlstyle-num.pl
>         Undefined sort subroutine "main::num" called at perlstyle-num.pl
> line 7.
>
>
> Comments?
>
>
> David
>
>
> [1] https://metacpan.org/dist/perl/view/pod/perlstyle.pod
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> https://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20210715/6636acf9/attachment.html>


More information about the SanFrancisco-pm mailing list