|
Last change
on this file was
17079,
checked in by westram, 7 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 | |
|---|
| 10 | use strict; |
|---|
| 11 | use warnings; |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | sub 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 | } |
|---|
| 30 | main(); |
|---|
Note: See
TracBrowser
for help on using the repository browser.