in reply to Re: Merge 2 strings like a zip
in thread Merge 2 strings like a zip
In keeping with your philosophy, here's something completely different :)
#!/usr/bin/perl # http://perlmonks.org/?node_id=1133857 use warnings; use strict; print zip("ABCDEFGHIJ", "abcde"), "\n"; sub zip { my ($str1, $str2) = @_; my $gap = length($str1) - 1; my $len2 = length $str2; join '', grep defined, "$str1$str2" =~ /(.)(?=.{$gap}(.)|.{$len2})/g +s; }
|
---|