MrSpoocy: grep dont return a ref to match.

Beitrag lesen

Hi,

here is a Simple example:

my $testdata = [{  
		'User'	=> [4545454,45354654,564656565],  
		'Amount'	=> 100,  
	},{  
		'User'	=> [2985454,4535345],  
		'Amount'	=> 187,  
	},{  
		'User'	=> [45,4654554],  
		'Amount'	=> 157,  
	},{  
		'User'	=> [2222],  
		'Amount'	=> 245,  
	},  
];  
  
my $tryToFind = 4654554;  

  
# Now i search for the entry, but i can not change :(  
if (grep {    grep {$_ eq $tryToFind}  @{$_->{'User'}}   } @{$testdata})  
{  
	$_->{'Amount'} = 158;  
	print "FOUND !";  
}  
print Dumper($testdata );  

  
# When i use this ... than work's  
foreach (grep { grep {$_ eq $tryToFind}  @{$_->{'User'}}  } @{$testdata})  
{  
	print "Got match " . $_->{"Amount"} . "\n";  
	$_->{"Amount"} = 158;  
}  
print Dumper($testdata );  

what is wrong with if ? If i found the User in the Array, than i need the ref to change the values from him. I will not copy the entry's

mfg Spoocy