Thank you all so much for your replies. I'll take some time and try them all out.
I think what I need to rewrite it so that it goes through the array. Most of these ideas work like a charm, assuming that the variable containing a string to be searched actually contains a noon interpolated variable ( IE the '$variable' and not the value of it ) That's what I need to figure out, how to do my search With $string not interpolated. Thanks all for your time and insight. Dan -----Original Message----- From: Jenda Krynicky [mailto:[EMAIL PROTECTED]] Sent: Tuesday, January 14, 2003 9:44 AM To: [EMAIL PROTECTED] Subject: RE: finding variable name in string From: "Dan Muey" <[EMAIL PROTECTED]> > Thanks for the reply. > > To simplify the question and not get off track I need to see if a > string contains a variable 'name' not 'value'. I guess we all got lost in what's the actuall variable name, what's to be interpolated when ad so forth. Let's try some selfcontained code: @strings = ( 'some code using $password; and some more code;', 'some accepted code;', ); foreach my $string (@strings) { if ($string =~ /\$password\b/) { print "$string\n\tcontains \$password\n\n"; } else { print "$string\n\tdoes not contain \$password\n\n"; } } Or assuming you have the variable name to search for in a variable #first way @strings = ( 'some code using $password; and some more code;', 'some accepted code;', ); $variable = "password"; foreach my $string (@strings) { if ($string =~ /\$$variable\b/) { print "$string\n\tcontains \$$variable\n\n"; } else { print "$string\n\tdoes not contain \$$variable\n\n"; } } #second way @strings = ( 'some code using $password; and some more code;', 'some accepted code;', ); $variable = '$password'; foreach my $string (@strings) { if ($string =~ /\Q$variable\E\b/) { print "$string\n\tcontains $variable\n\n"; } else { print "$string\n\tdoes not contain $variable\n\n"; } } HTH, Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]