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]