Looking around on google, it doesn't seem there is a direct equivalent. You'll have to write your own. Shouldn't be too difficult though. Any ol' search algorithm will do.
I was hoping not to have to do so. I could just do a foreach, or I could use join to splat the array out into a string and then grep the string. I was just hoping there was some kind of equivalent to that very handy PHP function, but I guess not.
I thought of that. However, I was hoping for something less verbose. I suppose as kernelm says, I could wrap that in a subroutine (returning a boolean ) and then call it as if it were a built-in function. I suppose having used PHP for so long now, going back to Perl feels like too much work.
Yes, a hash really is better in this case. Funny I didn't think of it because I've used three other hashes in this program so far. Grr. Argh!
BTW, major points for making your example use Whedonverse content. Shouldn't all programming examples work this way? ;-)
sub buffyBotSubRoutine_boolean001 {
# Are we allowed to pass a whole
# array as a param?
my @nest = shift;
my $wanted = "Spike";;
foreach my $vampire (@nest) {
if ($vampire eq $wanted) {
buffyBotSubRoutine_shagHim($vampire);
} else {
buffyBotSubRoutine_stakeHim($vampire);
}
}
}
(no subject)
Date: 2005-08-11 08:30 pm (UTC)(no subject)
Date: 2005-08-11 08:42 pm (UTC)foreach, or I could usejointo splat the array out into a string and then grep the string. I was just hoping there was some kind of equivalent to that very handy PHP function, but I guess not.(no subject)
Date: 2005-08-11 08:37 pm (UTC)my @array = qw(buffy angel firefly);
my $wanted = "angel";
foreach my $array_value (@array) {
if ($array_value eq $wanted) {
print "yay!\n";
} else {
print "boo!\n";
}
}
(no subject)
Date: 2005-08-11 08:44 pm (UTC)(no subject)
Date: 2005-08-11 08:49 pm (UTC)(no subject)
Date: 2005-08-11 09:14 pm (UTC)BTW, major points for making your example use Whedonverse content. Shouldn't all programming examples work this way? ;-)
(no subject)
Date: 2005-08-11 09:22 pm (UTC)You need to break upon finding a positive result. And only print a negative result at the end if there was no positie hit.
(no subject)
Date: 2005-08-11 09:33 pm (UTC)