How to determine of text matches?

G

Guest

In the code fragment below, I'm doing a substitution
of the key/value pairs in a hash using s/$key/$value/g;.
How can I determine if a match is found? I want to do
something like:

If (match found) {
print "FOUND MATCH";
}

-Thanks


#############################

return unless -T;

print "Processing==> $File::Find::name\n";

my $obj = tie(my @array, 'Tie::File', $_) || die "$!\n";

for (@array) {

while ((my $key, my $value) = each %strings) {

s/$key/$value/g;

}

}

untie @array;
 
J

Joe Smith

nospam said:
How can I determine if a match is found?

It's simple. Just test whether s/// returned true or not.
If (match found) {
print "FOUND MATCH";
}

if (s/$key/$value/g){
print "FOUND MATCH";
}

Any textbook that does not mention that should be thrown in the garbage.
-Joe
 
N

nobull

nospam said:
In the code fragment below, I'm doing a substitution
of the key/value pairs in a hash using s/$key/$value/g;.
How can I determine if a match is found?

You appear to have a question about the behaviour of s///g. Have you
considered looking up the explaination of the behaviour of s/// in the
Perl reference documentation?
I want to do something like:

If (match found) {
print "FOUND MATCH";
}

if ( s/$key/$value/g ) {
print "FOUND MATCH";
}

This newsgroup does not exist (see FAQ). Please do not start threads
here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top