We don't bite newbies here... much | |
PerlMonks |
Re: An efficient way to gather a common portion of several strings' beginningsby GrandFather (Saint) |
on Nov 15, 2015 at 11:34 UTC ( [id://1147723]=note: print w/replies, xml ) | Need Help?? |
Assuming none of your strings contain nulls:
Prints:
The xor operator ('^') combines the strings byte by byte and generates a null for each identical byte pair. @+ contains the offsets of the ends of matches. In this case the entire match is just the ticket so we use the first entry, 0, which is effectively the length of the common base. <Update: Fixed match issue pointed out by AnomalousMonk.
Premature optimization is the root of all job security
In Section
Seekers of Perl Wisdom
|
|