Thread Reihenfolge in einem Hash: haben "keys" und "values" die gleiche? (11 answers)
Opened by ronald at 2004-03-22 14:44

dominicn
 2004-03-22 15:28
#81190 #81190
User since
2003-08-08
327 Artikel
BenutzerIn
[default_avatar]
doch, es funktioniert so. solange du zwischen den beiden aufrufen den hashinhalt nicht aenderst jedenfalls.

kleines (hässliches) beispielprogramm:
Code: (dl )
1
2
3
4
5
6
%hash = ();
for (1..10) {
$hash{$_} = $_*$_;
}

print "keys: ", join " ", keys %hash, "\n", "values: ", join " ", values %hash;


und http://www.perldoc.com/perl5.6.1/pod/func/values.html sagt das auch:

Quote
Returns a list consisting of all the values of the named hash. (In a scalar context, returns the number of values.) The values are returned in an apparently random order. The actual random order is subject to change in future versions of perl, but it is guaranteed to be the same order as either the keys or each function would produce on the same (unmodified) hash.

View full thread Reihenfolge in einem Hash: haben "keys" und "values" die gleiche?