Leser: 22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; my $anzahl = 1000; my %hash; for (1..$anzahl) { $hash{'foo' . $_} = 'test'; } print "Pause, fertig definiert\n"; sleep 5; print "Laeuft weiter\n"; my $start = time (); for my $nr (1..$anzahl) { # $hash{'foo' . $nr} = "test$nr"; # Variante direkt %hash = &test (\%hash,$nr); # Variante mit sub } print "Laufzeit: " . (time () - $start) . " Sekunden\n"; sub test { my %hash = %{$_[0]}; my $nr = $_[1]; $hash{'foo' . $nr} = "test$nr"; return %hash; }
&test(\%hash, $nr);
%{$hash_ref}=();
1 2 3 4 5
sub test { my $hash_ref = $_[0]; my $nr = $_[1]; $hash_ref->{'foo' . $nr} = "test$nr"; }
test(\%hash,$nr);
QuoteIn fact, an identifier within such curlies is forced to be a string, as is any simple identifier within a hash subscript. Neither need quoting. Our earlier example, $days{'Feb'} can be written as $days{Feb} and the quotes will be assumed automatically. But anything more complicated in the subscript will be interpreted as an expression. This means for example that $version{2.0}++ is equivalent to $version{2}++ , not to $version{'2.0'}++ .
2010-01-25T09:58:37 pq[...]
wieso geht das bei dir und murphy fehlerfrei?