Thread push zu arrayref (33 answers)
Opened by Froschpopo at 2008-05-10 16:42

DanielH
 2008-05-10 22:45
#109528 #109528
User since
2007-11-15
54 Artikel
BenutzerIn
[default_avatar]
Froschpopo+2008-05-10 20:16:36--
hmm, also das funktioniert bei mir nicht:

Das ganze ist ein HTC-Loop:
Code (perl): (dl )
1
2
3
4
while (...) {
   push @loop, { ID => $id, DATUM => $datum, SPIELER => $spieler }
}
$param{SPORTART} = \@loop;


Nun will ich später eventuell außerhalb der while nochmal Elemente hinzufügen:
Code: (dl )
$param{SPORTART}->[$#$param{SPORTART}+1]->{DATUM} = 3;





Ich hab zwar keine Ahnung, was ein HTC-Loop sein soll, aber ist doch klar, dass das nicht funktioniert. Mit
Code: (dl )
$param{SPORTART}->[$#$param{SPORTART}+1]

hast du ja nur ein neues Element im @loop-Array ausgewählt, und keine Hash-Referenz (was du doch möchtest?!). Und einem Array-Element kann man nix per '->{DATUM} = 3' hinzufügen ;)

Mach besser so was:

Code: (dl )
grep { $_->{DATUM} = 3 } @$param{SPORTART}

wenn du jedem Hash {DATUM} hinzufügen möchtest.
Oder du packst einfach alle Hash-Referenzen in einen Hash, wenn du {DATUM} nur einmal global speichern willst

View full thread push zu arrayref