hello,
I'm strugling trying to write a simple check loop.
I have an array of hashes, I want to check the array and see if a hash key exists if it doesn't I want to push a hash into the array.
here is what I have...
I know the grep is doing a simple scalar match against each array index, how do I expand the code to do a check for a hash key in each array index?
I've gone blank! I need to use 'exists' don't i ?
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
I'm strugling trying to write a simple check loop.
I have an array of hashes, I want to check the array and see if a hash key exists if it doesn't I want to push a hash into the array.
here is what I have...
Code:
my @genmonths;
foreach my $gendoc (@gendocs){
if (! grep { $_ eq $gendoc->{'monthname} }@genmonths ) {
push @genmonths, {monthname => $gendoc->{'monthname},month => $gendoc->{'month'}};
}
}
I know the grep is doing a simple scalar match against each array index, how do I expand the code to do a check for a hash key in each array index?
I've gone blank! I need to use 'exists' don't i ?
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!