Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Merge 2 strings like a zip

by tel2 (Pilgrim)
on Jul 09, 2015 at 05:24 UTC ( [id://1133878]=note: print w/replies, xml ) Need Help??


in reply to Re: Merge 2 strings like a zip
in thread Merge 2 strings like a zip

Thanks for that, Anonymous Monk!

I don't fully understand it yet, but it looks beautiful. 8)

That's the first time I've seen /K and /r.  No problems with /K, but my webhost is still using v5.10.1 and I see that /r didn't come in until 5.14.  So how could I write that without the /r modifier?  I think I understand what /r is supposed to do, but I don't yet understand your code enough to replace it in this context.

I've added a 2nd (unzip) function request, below, which I'd appreciate your input on, if you have time.

Thanks again.

Replies are listed 'Best First'.
Re^3: Merge 2 strings like a zip
by Anonymous Monk on Jul 09, 2015 at 14:41 UTC

    zip() without /r and unzip()

    #!/usr/bin/perl # http://perlmonks.org/?node_id=1133857 use warnings; use strict; print zip("ABCDEFGHIJ", "abcde"), "\n"; print "@{[ unzip('AaBbCcDdEeFGHIJ', 5) ]}\n"; sub zip # if no /r { my ($str1, $str2) = @_; $str1 =~ s/.\K/ substr $str2, 0, 1, ''/ges; $str1 } sub unzip { my ($input, $length2) = @_; return join('', unpack "(ax)$length2 a*", $input), join '', unpack "(xa)$length2", $input; }
      Nice work, Anonymous Monk!

      Thanks again.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1133878]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-16 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found