1 2 3 4 5
my %landab = ( "austria" => "a", "belgium" => "b", "switzerland" => "ch", "germany" => "d");
1 2 3
while ( my( $key, $val ) = each %landab ) { print "$key\n" if $val eq 'a'; }
my %abland = reverse %landab;
my $aland = {reverse %landab}->{a};
1 2 3 4 5 6
my %landab = ( "austria" => "a", "belgium" => "b", "switzerland" => "ch", "germany" => "d" );
switzerland, ch, austria, a, germany, d, belgium, b
b, belgium, d, germany, a, austria, ch, switzerland
2011-05-23T13:06:34 pqdann markiere doch bitte den thread als gelöst.
my $aland = {reverse %landab}->{a};
1 2 3 4 5 6 7 8 9 10 11 12 13
use Benchmark qw/cmpthese/; my %landab = ( "austria" => "a", "belgium" => "b", "switzerland" => "ch", "germany" => "d" ); cmpthese( 0, { hash => sub { my %badnal = reverse %landab; my $land = $badnal{a}; }, anon => sub { my $land = {reverse %landab}->{a}; }, });
$landab{'austria'.$_} = 'a'.$_ for (1..1e5);
1 2 3 4 5 6 7
print "RAM-Verbrauch des Perl-Prozesses erstmals ermitteln, [Enter]\n"; <>; #my %abland = reverse %landab; #my $aland = $abland{a}; my $aland = {reverse %landab}->{a}; print "RAM-Verbrauch des Perl-Prozesses zum zweiten Mal ermitteln, [Enter]\n"; <>;
2011-05-23T16:31:08 payxMein Fazit: TIMTOWTDI. In der Regel dürfte es ziemlich egal sein, wie man hier verfährt.