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: Advanced:
string comparison in perl

 



sshiva
New User

Apr 8, 2005, 6:05 PM

Post #1 of 7 (1693 views)
string comparison in perl Can't Post

hello all

could anyone guide me as to how can i compare two strings in perl? what i need is a "string diff" code that compares two strings and returns the "difference" between the two

eg:

string1 = "this is a test";
string 2 = "this is a";

returns " test" as the result

any suggestions/ideas appreciated

warm regards

shiva


KevinR
Veteran


Apr 9, 2005, 11:41 AM

Post #2 of 7 (1691 views)
Re: [sshiva] string comparison in perl [In reply to] Can't Post

this should have been posted in the beginner forum, but here is one way:


Code
my $string1 = "this is a test"; 
my $string2 = "this is a";
(my $string3 = $string1) =~ s/$string2//;
print $string3;

-------------------------------------------------


sshiva
New User

Apr 12, 2005, 11:32 AM

Post #3 of 7 (1674 views)
Re: [KevinR] string comparison in perl [In reply to] Can't Post

thanks kevin. sorry about posting this here as i needed a quick response to my answer and thanks to you, i indeed got it. Smile

i have another query and would appreciate if you could suggest me a workaround.

i have this text file basically containing a lot of object ids (OID) that i need to extract. there is no standard format for this file and OID's appear everywhere. It would be nice if i could extract all these OID's and dump them into an array or maybe another text file

please advise

regards

shiva


sshiva
New User

Apr 12, 2005, 11:35 AM

Post #4 of 7 (1673 views)
Re: [sshiva] string comparison in perl [In reply to] Can't Post

i forgot to mention that the OID's have the following format.
19-0006f06f-e8c5-119c-929b-80c79891304d. its a combination of hex/dec digits


KevinR
Veteran


Apr 12, 2005, 4:49 PM

Post #5 of 7 (1663 views)
Re: [sshiva] string comparison in perl [In reply to] Can't Post

You will need to post some sample lines from the text file to look at so someone can try and make some suggestions.
-------------------------------------------------


chaoslawful
New User

Nov 10, 2005, 9:06 AM

Post #6 of 7 (1575 views)
Re: [KevinR] string comparison in perl [In reply to] Can't Post

well, Algorithm::LCSS would be a better way in my opinionSmile


KevinR
Veteran


Nov 10, 2005, 9:55 AM

Post #7 of 7 (1573 views)
Re: [chaoslawful] string comparison in perl [In reply to] Can't Post

very good, but maybe you could post your suggestion sooner next time? This thread is about 7 months old. But maybe better late than never. I never heard of that module but will take a look at it for future reference. Smile
-------------------------------------------------

 
 


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

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