Thread Knotennamen aus einem Array nach Domain sortieren (9 answers)
Opened by toby at 2012-01-24 10:09

Linuxer
 2012-01-24 11:48
#155629 #155629
User since
2006-01-27
3875 Artikel
HausmeisterIn

user image
Dein Shell-Code enthält doch bereits Perl-Code, der das umsetzt.

Hier mal eine Variation:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /usr/bin/perl
use strict;
use warnings;

my @nodes = qw(
db.blah.org
de.yahoo.com
mail.example.org
www.aol.com
www.example.org
www.freshmeat.net
www.hotdoggie.com.au
www.blah.org
);

# Schwartzian Transform
my @sorted =
  map { $_->[0] }
    # sort by domain
    sort { $a->[1] cmp $b->[1] }
      # "extract" domain.tld
      map { [ $_, join '.', (split m/\./)[-2,-1] ] }
        @nodes;


# check result
{
    local $, = local $\ = $/;
    print @sorted;
}
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!

View full thread Knotennamen aus einem Array nach Domain sortieren