Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: without looping, check if $var is found in @list

by duckyd (Hermit)
on Dec 15, 2006 at 02:32 UTC ( [id://589972] : note . print w/replies, xml ) Need Help??


in reply to Re: without looping, check if $var is found in @list
in thread without looping, check if $var is found in @list

Using string interpolation on the array is a bad idea - it won't neccessarily get you what you want. For example:
#!/usr/bin/perl -w use strict; use warnings; my @list = ('jumping turtle', 'frog', 'tadpole'); my $var = "turtle"; if ("@list" =~ /\b$var\b/) { print "yup\n"; }
happily reports a match even though just "turtle" doesn't appear in the array, it's a "jumping turtle". I would be reluctant to assume that such behavior is desirable...