Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • $a=~s/(?<=.)/$b=~m|.|g;$&/ge;
    • hmms... nice bunch of characters :-) Interesting result :-) Perl rockz :-) You Rockz :)
      • Actually I originally did it like this, just to have a substitution inside a substitution:


        But I decided that destroying $b in the process might not be acceptable.

  • sub zip {
        my( $a, $b ) = @_;
        my $res;
        $res .= chop($b).chop($a) for 1..length($a);
        scalar(reverse $res);
    • Nice. We all forget chop :-)
      • I long ago proposed, on perl5-porters, an operator "chip" that would take one char from the front of a string, the way chop takes a character from the end. That would get around the need to reverse the chopped together $res.
        • Chip sounds cool... can remember computer chips but also food O:-)

          During our discussion about an "interesting" solution, we could take advantage of chip. We thought of unshift, but that doesn't work for arrays.

          • The computer chip I referred to in the original proposal was Chip Salzenburg, who was working on Topaz (the original potential perl6) at the time, had established The Perl Foundation, and was the original pumpking (after Larry), so sneaking an honorarium mention of him into the language seemed reasonable.
          • We thought of unshift, but that doesn't work for arrays. s/arrays/strings/;

            Much like your original proposal, you can use:

            @a = split //, $a;
            @b = split //, $b;
            my $res .= (shift @a) . (shift @b) while @a;
            • That was almost my first solution:
              @a = split //, $a;
              @b = split //, $b;
              while (@a) {
                push @c, shift(@a), shift(@b)
              $c = join "",@c;
  • Just wait a while, perl6 will have a zip operator (the Yen currency symbol) that merges two lists in interleaved order.
  • $b=~s!!$a=~/./g;$&!ge

    The zip in my solution is in $b.

    Casey West