On Thu, 20 Feb 2014 15:05:42 -0600, Matt wrote:
>my @alarm = ("xyz", "abc");
>>my $name = "ab";
>>unless (grep {/$name/} @alarm) { # do this }
>my @alarm = ("xyz", "abc");
>>my $name = "ab";
>>unless (grep {/$name/} @alarm) { # do this }
>If I set 'my $name = "abc";' it seems to match. But I want to match
>on "ab" as well.
It appears to do this already.
#!/usr/bin/perl -w
use 5.14.0;
my @alarm = ("xyz", "abc");
my $name = "ab";
my $name1 = "abc";
# Check "ab".
unless ( grep { /$name/ } @alarm ) {
say "$name not found";
} else {
say "$name found";
}
# Check "abc".
unless ( grep { /$name1/ } @alarm ) {
say "$name1 not found";
} else {
say "$name1 found";
}
[OUTPUT]
ab found
ab found
abc found
--
Peter Gordon, pete...@netspace.net.au on 02/21/2014
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/