Never mind this one; I figured it out with the other replies... Thanks,
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Daniel Rychlik Sent: Friday, April 21, 2006 1:37 PM To: Brian Raven; [email protected] Subject: RE: Updating Hash Elements What if I wanted to update another anonymous hash on the fly? Lets say in a threaded loop I am keeping up with connection attempts and if they fail, I take the key from one anonymous hash and update another anonymous hash with that KEY and how many attempts... So, $ConnectionAttempts{'JOBID'} = { 'attempts' => +1 }; That doesn't work, how would you guys do it? -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Brian Raven Sent: Friday, April 21, 2006 12:08 PM To: [email protected] Subject: RE: Updating Hash Elements Daniel Rychlik <> wrote: > Hello, > > How does one update a hash element in PERL? See 'perldoc -q "Perl.*and.*perl"' > > I am using anonymous hashes to process a file, and each element in > the anonymous has its own value... > > If the file has success on process, I delete the hash element from > the anonymous hash... > > If it the file fails to process, I need to increment the attempts to > the next higher number... > > I tried this, > > If ($HASH{KEY}->{attempts} != '5') { > > $attempted = $HASH{KEY}->{attempts} + '1'; Loose the quotes in the above 2 lines. They are numbers, not strings. > > $HASH{KEY}->{attempts} => $attempted; #Update the hash key That should be assignment (i.e. '='), not the special comma operator (i.e. '=>'). However, it is a lot simpler to use the pre- or post-increment operators. For example: ++$HASH{KEY}->{attempts}; See 'perldoc perlop'. > > } else { > > Move the file to the error folder... > > } > > When I run it, I get "Useless use of hash element in void context. > Useless use of private variable in void context... > > How could this better be written? HTH -- Brian Raven ================================= Atos Euronext Market Solutions Disclaimer ================================= The information contained in this e-mail is confidential and solely for the intended addressee(s). Unauthorised reproduction, disclosure, modification, and/or distribution of this email may be unlawful. If you have received this email in error, please notify the sender immediately and delete it from your system. The views expressed in this message do not necessarily reflect those of Atos Euronext Market Solutions. L'information contenue dans cet e-mail est confidentielle et uniquement destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail vous parvient par erreur, nous vous prions de bien vouloir prevenir l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre systeme. Le contenu de ce message electronique ne represente pas necessairement la position ou le point de vue d'Atos Euronext Market Solutions. _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
