Thread Hashvalues nach Variablen sortieren: SCHWER (25 answers)
Opened by Gast at 2004-09-01 16:49

renee
 2004-09-01 18:34
#49759 #49759
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Das hier ist bestimmt ein Anfang für Dich:
Code: (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/perl

use strict;
use warnings;

my %hash = ();

while(my $line = <DATA>){
 chomp $line;
 my @array = split(/\s+/,$line);
 $hash{$array[1]} = [@array[2,3,4,0,6,5]];
}

my @sorted_keys = sort{change_time($hash{$a}->[3],$hash{$a}->[4]) <=>
                        change_time($hash{$b}->[3],$hash{$b}->[4])}keys %hash;

print "\nFlugnummer\tDatum     \tUhrzeit\t",
sprintf("%15s",'Zielort'),"\t",sprintf("%15s",'Abflugort'),
"\tTerminal\tAnkunft\n";
foreach(@sorted_keys){
 print sprintf("%10s",$_),"\t",
       sprintf("%10s",$hash{$_}->[3]),"\t",
       sprintf("%7s",$hash{$_}->[4]),"\t",
       sprintf("%15s",$hash{$_}->[0]),"\t",
       sprintf("%15s",$hash{$_}->[1]),"\t",
       sprintf("%9s",$hash{$_}->[2]),"\t",
       sprintf("%7s",$hash{$_}->[5]),"\n";
}


sub change_time{
 my($date,$clock) = @_;
 $clock =~ s/\://;
 return join("",reverse split(/\./,$date)).$clock;
}
# hier Leerzeichen weglassen
_ _DATA_ _
30.07.2004 123456 Malaga Bielefeld C 12:15 11:31
23.07.2004 654321 Berlin Bielefeld D 13:00 12:58
04.07.2004 587931 Barcelona Bielefeld E 14:00 12:00
30.07.2004 356987 Muenchen Bielefeld A 12:50 12:00
30.07.2004 879652 Koeln Bielefeld B 12:55 12:15
30.07.2004 456987 Bonn Bielfeld H 14:00 11:55
05.08.2004 456789 Freiburg Bielfeld C 15:00 13:00
01.09.2004 336632 Berlin Bielefeld B 22:00 19:00


Ausgabe:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
~/entwicklung 54> perl flug.pl

Flugnummer      Datum           Uhrzeit         Zielort       Abflugort Terminal        Ankunft
   587931      04.07.2004        12:00       Barcelona       Bielefeld         E         14:00
   654321      23.07.2004        12:58          Berlin       Bielefeld         D         13:00
   123456      30.07.2004        11:31          Malaga       Bielefeld         C         12:15
   456987      30.07.2004        11:55            Bonn        Bielfeld         H         14:00
   356987      30.07.2004        12:00        Muenchen       Bielefeld         A         12:50
   879652      30.07.2004        12:15           Koeln       Bielefeld         B         12:55
   456789      05.08.2004        13:00        Freiburg        Bielfeld         C         15:00
   336632      01.09.2004        19:00          Berlin       Bielefeld         B         22:00
\n\n

<!--EDIT|renee|1094049410-->
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Hashvalues nach Variablen sortieren: SCHWER