Search notes:

Perl function: sort

use warnings;
use strict;

use Lingua::EN::Numbers qw(num2en_ordinal);

my @csv_like_array = qw (
one;4;1
two;8;2
three;9;3
four;5;4
five;2;5
six;1;6
seven;6;7
eight;3;8
nine;7;9
);

# sort_on_nth_column(1); # TOOD, currently not possible as <=> is used in column_value(). The first column would require a «cmp».
sort_on_nth_column(2);
sort_on_nth_column(3);

sub sort_on_nth_column { # {{{

  my $n = shift;

  print "\n\nSort on " . num2en_ordinal($n) . " column\n\n";

  my @sorted = sort { column_value($n-1) } @csv_like_array;
  
  # print "count after: " . scalar @a . "\n";
  
  print join "\n", @sorted;
  
} # }}}

sub column_value { # {{{

    my $col = shift;

    (split(";", $a))[$col] <=> 
    (split(";", $b))[$col]
} # }}}
Github repository about-perl, path: /functions/sort.pl

See also

Perl functions
R function: sort, Shell command: sort, vim script: sort

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758190069, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Perl/functions/sort(82): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78