Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > How to determine of text matches?

Reply
Thread Tools

How to determine of text matches?

 
 
nospam
Guest
Posts: n/a
 
      08-21-2004
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;


 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      08-22-2004
nospam wrote:

> 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
 
Reply With Quote
 
 
 
 
nobull@mail.com
Guest
Posts: n/a
 
      08-22-2004
nospam <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Library - to determine whether given text is in English ? anonym Java 8 03-18-2008 01:36 AM
Determine value in text box JK Javascript 3 04-05-2005 09:26 PM
nuby: determine method passed and determine the receiver that received the method Peņa, Botp Ruby 1 01-24-2004 07:51 PM
Determine user-selected text Jeff S ASP .Net 1 01-23-2004 01:06 AM
Determine file type (binary or text) Sami Viitanen Python 21 08-16-2003 02:27 AM



Advertisments