in reply to without looping, check if $var is found in @list
It should be pointed out your example is, i believe; horrendously wrong. In:
if ($var=~ m/@list/ ){ print 'ok'; }
What you are doing is attempting to match the @list inside of $var, and we know that $var does not hold all those things.
This would have worked:
#!/usr/bin/perl -w use strict; use warnings; my @list = qw(frog turtle tadpole); my $var = "turtle"; if ("@list" =~ /\b$var\b/) { print 'yup'; } # using quotes, we coerce the array to act as a string else { print 'nope'; }
We didn't have to place the \b for this example to appear as if it worked. The \b means word boundary. Otherwise, we would match on 'turtles' and 'turtley'.
the idea is : $lookinside =~ /$for/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: without looping, check if $var is found in @list
by duckyd (Hermit) on Dec 15, 2006 at 02:32 UTC | |
|
Re^2: without looping, check if $var is found in @list
by ikegami (Patriarch) on Dec 15, 2006 at 04:49 UTC |