Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: If there a way to find the location of the first difference between two strings?

by jwkrahn (Abbot)
on Mar 26, 2012 at 09:33 UTC ( [id://961631]=note: print w/replies, xml ) Need Help??


in reply to Re: If there a way to find the location of the first difference between two strings?
in thread If there a way to find the location of the first difference between two strings?

use 5.010; my $t = $s1 ^ $s2; my ($f) = $t =~ /^(\x{00}*)/; say length $f;

Another way to do that:

use 5.010; my $t = $s1 ^ $s2; $t =~ /^\0*/ && say $+[0]
  • Comment on Re^2: If there a way to find the location of the first difference between two strings?
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: If there a way to find the location of the first difference between two strings?
by flexvault (Monsignor) on Mar 26, 2012 at 10:36 UTC

    JavaFan and jwkrahn,

    C o o l !

    That's the code I was hoping for...

    Need to benchmark now!

    UPDATE: My apologies to JavaFan, I didn't realize his post was first. Both solutions Benchmarked are better than mine (376%).

    Thank you

    "Well done is better than well said." - Benjamin Franklin

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://961631]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-23 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found