hotti: grep dont return a ref to match.

Beitrag lesen

hi,

Now i search for the entry, but i can not change :(

if (grep {    grep {$_ eq $tryToFind}  @{$_->{'User'}}   } @{$testdata})

This 'if'-control is always TRUE. Btw., using grep, consider meaning $_ in block{}.

The better way, step by step, using two loops:

  
# @{$testdata} is a list of hash-references, 1st loop:  
foreach my $href (@{$testdata}){  
	# each hash contains a list of numbers in attribute {User}  
	# second loop:  
	foreach my $user( @{$href->{User}}){  
		if($user == $tryToFind){ # numeric comparison  
			# now, we can change the value for {Amount}  
			# direct access  
			$href->{Amount} = 158;  
		}  
	}  
}  

Hotti