In a message dated 4/21/2006 12:30:31 P.M. Eastern Standard Time, [EMAIL PROTECTED] writes:
 
> Hello,
>
> How does one update a hash element in 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';
>
>     $HASH{KEY}->{attempts} => $attempted; #Update the hash key
 
 
typo alert:  i think what you want in the preceding line is not => (fat comma),
but = (assignment); this would give you incrementation.  
 
in any event, the two preceding lines could be more concisely written as:   
 
    ++$HASH{KEY}->{attempts};
>
> } 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?
>
> -Dan
 
 
hth -- bill walters  
 
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to