Thread Sehr Komplizierte Sortierung eines Arrays
(5 answers)
Opened by cbxk1xg at 2009-10-12 16:07
So würde ich es angehen:
(ungetestet) 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 $basedir='/path/to/files/'; my @filelist=qw(irgenwas12 irgenwas34 irgenwas56 irgenwas78 irgenwas90); for my $file (@filelist) { my $date=''; my $name=$file; open(my $fh, '<', $basedir.$file) or die("ERROR open $basedir$file ($!)\n"); while(my $line=<$fh>) { ($date)=$line=~/^\{datestamp=(\d{12})\}/); last if($date); } close($fh); $file={name=>$name,date=>$date}; } @filelist=sort{$a->{date} cmp $b->{date}}@filelist; for my $file (@filelist) { print $file->{name}; print $file->{date}?' ('.$file->{date}.')':' (NO DATE FOUND)'; print "\n"; } Last edited: 2009-10-12 16:42:43 +0200 (CEST) |