----- Original Message -----
From: Daniel Rychlik
Sent: 4/21/2006 11:56:49 AM
To: [email protected]
Subject: Updating Hash Elements
> If ($HASH{KEY}->{attempts} != '5') {
# You are comparing a quoted string using
# the numerical not-equal operator. Pick
# a type and stick to it. I rather use numeric:
if ($HASH{KEY}->{attempts} != 5) {
> $attempted = $HASH{KEY}->{attempts} + '1';
# Why not assign the attempts directly>
# Note that the first time it is encountered,
# the key will be created and incremented to 1.
# Works out too, since we are comparing it
# numerically above.
$HASH{KEY}->{attempts}++;
>
> $HASH{KEY}->{attempts} => $attempted; #Update the hash key
# This should be:
$HASH{KEY}->{attempts} = $attempted;
# But since we are updating it directly above,
# it is unnecessary.
> When I run it, I get "Useless use of hash element in void context.
> Useless use of private variable in void context...
That's because you are assiging with the => operator instead of the =
operator. The => operator is actually an alias to a comma so that you can more
cleanly view the relationship between key and values instead of viewing it as a
flat list. So these two statements are equivalent:
$foo = ( 'key1' => 'value1', 'key2' => 'value2' );
$foo = ( 'key1], 'value1', 'key2', 'value2' );
-dZ.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs