CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
String match

 



msds
User

Sep 24, 2003, 3:55 AM

Post #1 of 3 (204 views)
String match Can't Post

Smile Hello,
Consider this bit of code:

Code
$stri1="testing"; 
$stri2="test";
if($stri1=~ $stri2)
{
print "\nMatched";

}


A match is found between $stri1 ("testing")and $stri2 ("test")if $stri2 is only a substring of $stri1 i.e. "test".

How can we change the above code to match when $stri2 is
exactly the same string as $stri1?

i.e. both $stri1 and $stri2 are "testing".
Thanx,
msdsSmile


KevinR
Veteran


Sep 24, 2003, 8:57 AM

Post #2 of 3 (202 views)
Re: [msds] String match [In reply to] Can't Post

two ways I can think of:



print "\nMatched" if ($stri1 eq $stri2) ;



and



print "\nMatched" if ($stri1 =~ m/^$stri2$/);



^ : begining of string anchor

$ : end of string anchor
-------------------------------------------------


(This post was edited by KevinR on Sep 24, 2003, 8:59 AM)


msds
User

Sep 26, 2003, 3:02 AM

Post #3 of 3 (188 views)
Re: [KevinR] String match [In reply to] Can't Post

Smile The eq works.
Thanks,
msdsSmile

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives