1 2 3 4 5 6 7 8 9 10 11 12
#!/usr/bin/perl -w use strict; use warnings; my %test = ( foo1 => 'a', foo2 => 'b', ); if (exists $test{"foo\d"}) { print "ja\n"; }
1 2 3 4 5 6 7 8 9 10 11 12
#!/usr/bin/perl -w use strict; use warnings; my %test = ( foo1 => 'a', foo2 => 'b', foo10 => 'c', ); my ($letzter) = sort {substr ($b,3) <=> substr ($a,3)} grep {$_ =~ /^foo\d+$/} (keys %test); print "$letzter\n";
2011-11-07T17:40:40 pqwenn du nur den höchsten wert brauchst, nimmst du generell List::Util::max statt sort
1 2
# ungetestet my $max = 'foo' . max( map { /^foo(\d+)$/ ? $1 : () } keys %test );