Hallo, Am Wed, 19 Jan 2005, Christian Boltz schrieb: [..]
foreach (sort(keys(%hash))) { $tmp = $_; print "$tmp\n"; %tmphash = $hash{$tmp}; foreach (sort(keys(%tmphash))) { print " " . $_ . " " . $tmphash{$_} . "\n"; } } [..] Wo liegt mein Fehler?
Das hat Michael schon geschrieben ;)
Ich vermute, dass die Zuweisung %tmphash = ... so nicht richtig ist, habe aber auch nach längerem Austesten und Lesen von man perlref nicht die richtige Syntax gefunden :-(
Die Fehlermeldung haette dich auf die Spur bringen koennen:
Reference found where even-sized list expected at ./testcase.pl line 16. Use of uninitialized value in concatenation (.) or string at ./testcase.pl line 18. HASH(0x8151cd4)
Die Zuweisung an ein Hash "%foo = ..." erwartet eine Liste mit einer geraden Anzahl Elemente, z.B.: "= ( key1, val1, key2, val2)". Ein Hash ist in perl5 ja ein Sonderfall einer Liste. Du uebergibst aber nur die Referenz auf ein Hash, also einen Skalar. Die Zweite Meldung ist dann nur der Folgefehler beim Zugriff auf $tmphash{$_}. -dnh -- I ask you lot, as experts in kicking people in the nuts, do you ever pause in the middle of doing so and ask the victim for a favour? Do you get indignant if they are somewhat less than ethusiastic about performing that favour seeing as how you asked for it right after savaging them once and and right before savaging them again? -- Paul Tomblin