δΊ 2010-10-31 21:43, Thorsten Scherf ει:
Hi,
I have an array with anonymous hash references like the following:
$foo = [ {
name = value,
id = value,
},
{
name = value,
id = value,
}
];
Iterating through the hash references works with:
foreach $item (@$foo) {
do something with $item->name;
}
I think what you want is the code like:
use strict;
my $foo = [ {
name => 'foo',
id => 1,
},
{
name => 'bar',
id => 2,
}
];
print check_for_exists('name','foo');
sub check_for_exists {
my $key = shift;
my $value = shift;
for my $item (@$foo) {
if ($item->{$key} eq $value ) {
return 1;
}
}
return 0;
}
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/