Daniel Rychlik 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 };
> 
> That doesn't work, how would you guys do it?

You do it the same way you did the original.  There is nothing magical
about hashes.  They are just fancy variables.  You assign and
increment them in the normal way.

    $connectionAttempts{JOBID}->{attempts}++;

Note that you don't need quotes around your hash keys and it generally
makes for cleaner code to leave them out.

You can also simplify a bit more.  You don't need the explicit
dereference between the two hash elements.  This is equivalent:

    $connectionAttempts{JOBID}{attempts}++;

Which version you use depends on your preferences.

If either "JOBID" or "attempts" does not exist in the hash, it will be
automatically created and initialized to undef (which is numerically
equal to zero) when you access it.

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

Reply via email to