in reply to Merge 2 strings like a zip
"TIMTOWTDI"
My 2 ¢:
use warnings; use strict; use feature qw(say); sub zip; say zip 'ABCDEFGHIJ', 'abcde'; sub zip { join "", sort { lc $a cmp lc $b } split "", $_[0] . $_[1]; } __END__
I guess it's slower than some of the examples above but it doesn't look bad ;-)
And i learned something. See Strange Observation [SOLVED] for details. Thanks to toolic, KurtSchwind, Athanasius and some unknown soldier.
Update: Same benchmark as used by BrowserUK:
karls-mac-mini:monks karl$ ./benchzip.pl Rate B Karl A C B 98641/s -- -17% -44% -68% Karl 118153/s 20% -- -33% -62% A 176987/s 79% 50% -- -43% C 312785/s 217% 165% 77% --
Regards, Karl
«The Crux of the Biscuit is the Apostrophe»
|
---|
Replies are listed 'Best First'. | |
---|---|
The Regex Approach: Merging 2 strings like a zip
by pat_mc (Pilgrim) on Jul 11, 2015 at 11:59 UTC | |
by Anonymous Monk on Jul 11, 2015 at 18:43 UTC | |
Re^2: Merge 2 strings like a zip
by tel2 (Pilgrim) on Jul 12, 2015 at 23:44 UTC | |
by karlgoethebier (Abbot) on Jul 13, 2015 at 07:07 UTC |