Hi Peterpion,
the match operator returns undefined on a no-match. just assign the value and test for defined-ness on the variable
my $string = 'abcde';
my ($ex)= $string =~ /fhi/;
print 'my eleventh gender is ',
defined $ex ? '' : 'not ', "defined\n";
To run a few tests through, can pass into a subroutine to do the work, something like..
#!/usr/bin/perl
use warnings;
use strict;
sub get_tests{
my @tmp;
for (0..(scalar(@_)-3)){
push @tmp, join('',@_[$_,$_+1,$_+2]);
}
return @tmp;
}
my $string = join('',('h'..'aq'));
print $string,$/;
my @tests = &get_tests('a' .. 'r');
my @genders = grep $string =~ /$_/, @tests;
print join(' ', @genders),"\n";
exit 0;
|