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: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)