Thread Performance bei Suche in Hashkeys
(14 answers)
Opened by bianca at 2011-02-26 14:30
Wenn Du mit dem Hash in der gegebene Form arbeiten musst, ist first() aus List::Util Dein Freund, da grep nicht per last verlassen werden kann:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #!/usr/bin/perl -w use strict; use warnings; use List::Util qw(first); my %test = ( '15.01.2011' => defined, '17.01.2011' => defined, '13.02.2011' => defined, '16.03.2011' => defined, '20.12.2011' => defined, ); foreach my $m (1..12) { if (first { /\.0?$m\./ } keys %test) { print "Monat $m gefunden!\n"; } } Editiert von FIFO: typo Last edited: 2011-02-26 21:23:49 +0100 (CET) Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? -- Brian Kernighan: "The Elements of Programming Style"
|