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/
In reply to Re: without looping, check if $var is found in @list
by leocharre
in thread without looping, check if $var is found in @list
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |