source: trunk/PERL_SCRIPTS/ACI/sortListNumeric.pl

Last change on this file was 17079, checked in by westram, 6 years ago
  • add script usable from ACI (sort words numerically)
  • Property svn:executable set to *
File size: 561 bytes
Line 
1#!/usr/bin/perl
2#
3# Usage as arb ACI, e.g.:
4#
5#     readdb(test)|exec(sortListNumeric.pl)
6#
7# - reads data to sort from field 'test' (single entries in data need to be space separated)
8# - sorts all entries numerically and concatenates them (into one new data entry)
9
10use strict;
11use warnings;
12
13
14sub main() {
15  my $line = <STDIN>;
16  chomp($line);
17  my @words = split /\s+/, $line;
18
19  my @sorted = sort {
20    my $cmp = $a <=> $b;
21    if ($cmp==0) {
22      $cmp = $a cmp $b;
23    }
24    $cmp;
25  } @words;
26  my $sline = join ' ',@sorted;
27
28  print "$sline";
29}
30main();
Note: See TracBrowser for help on using the repository browser.