go ahead... be a heretic | |
PerlMonks |
Re: Merge 2 strings like a zipby sundialsvc4 (Abbot) |
on Jul 09, 2015 at 11:50 UTC ( [id://1133945]=note: print w/replies, xml ) | Need Help?? |
Just to show the crowd that I can, in fact, whip-up a “one-liner” ...
If you really, really, know that one string is always shorter than the other, then this problem simply consists of taking a character from both strings until the shorter string is exhausted. Then, you append the remainder of the first (longer) string. But I wouldn’t make such an assumption. I would allow either string to be longer:
“Elegant?” “Not?” My response is the same as Rhett Butler’s. The algorithm can be demonstrated to work in every case, by accompanying tests, and it is easy to eyeball it. And, yes ... if I had any other reason to install and use an existing CPAN module that can zip a string, I would use that module. I probably would not install it, just to zip a string, since the alternative is trivial.
In Section
Seekers of Perl Wisdom
|
|