[EMAIL PROTECTED] wrote:
> 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 };
        $ConnectionAttempts{KEY}{attempts} += $HASH{KEY}->{attempts};
        use Data::Dumper to look at your data and it helps in seeing what you 
need to do to access the data.

Wags ;) ps using values from your initial posting.

> 
> 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



*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to