in reply to Merge 2 strings like a zip

G'day tel2,

Here's my offering. It just uses length and substr. There's no: concatenation; splitting strings into lists; regexes; or modules to load.

#!/usr/bin/env perl -l use strict; use warnings; print zip("ABCDEFGHIJ", "abcde"); sub zip { my ($str1, $str2) = @_; for (0 .. length $str2) { substr $str1, $_ * 2 + 1, 0, substr $str2, $_, 1; } return $str1; }

Output:

AaBbCcDdEeFGHIJ

-- Ken

Replies are listed 'Best First'.
Re^2: Merge 2 strings like a zip
by tel2 (Pilgrim) on Jul 09, 2015 at 07:07 UTC
    G'day mate.

    Awesome work from across the ditch!

    Thanks.