On Thu, 20 Feb 2014 13:04:56 -0600, Matt wrote:
>Having trouble making this work.
>
>my @alarm = ("xyz", "abc");
>my $name = "ab";
>unless (grep {/$name/} @alarm) { # do this }
>
>Since "ab" is contained in the array I want it to NOT 'do this'.
>What
>have I got wrong?
>
Use word boundaries
#!/usr/bin/perl -w
use 5.14.0;
 
my @alarm = ("xyz", "abc");
my $name = "ab";
unless (grep {/\b$name\b/} @alarm) { print "Not in array!\n" }

--
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/

Reply via email to