in reply to Loop to merge every two columns

use strict; while (<DATA>) { s/( \w) /$1/g; print; } __DATA__ 3851 A A G G T T 3854 A A G G T T

Or as a one liner

perl -pi.bak -e 's/( \w) /$1/g' file.dat

And if you want to use "newer" regex features, the following is shorter:

s/ \w\K //g;

Replies are listed 'Best First'.
Re^2: Loop to merge every two columns
by JavaFan (Canon) on May 12, 2011 at 09:33 UTC
    Note that those "newer" regex features are present in all versions of Perl that aren't "end-of-life". The last major version of Perl that didn't have those was 5.8, which dates from July 2002 - less than a year after the release of IE 6.

      Yes, I provide some programming work for a couple non-profits that run perl 5.8 and perl 5.10 respectively. As a consequence, I don't always get to utilize the latest and greatest.

      And even though the 5.10 EOL was announced, I find that a lot of posters aren't always on a current version of perl. Therefore sometimes it's easier to just assume they don't have access to certain features.

      I definitely appreciate the \K marker though, and use it plenty now to clean up regex's when I can.

        Therefore sometimes it's easier to just assume they don't have access to certain features.
        Sure, but where do you stop? Perhaps people should stop argueing to use "modern" 3-arg open and autovivifying file handles as well? Moose would be right out, now that it's dropping support for 5.8. Perhaps we shouldn't even assume they have Perl 5. (5.8 was released 8 years after 5.000; we're now 9 years after the release of 5.8 - if we let 5.000 coincide with the presumed birth of Jesus, and 5.14 now, 5.8 was released in the middle of the 10th century (Vikings discover America), and 5.10 in the 16th (right after the Middle Ages)).

        I think that after 3.5 years, 2 major releases, and an EOL announcement, we should stop the "oh, let's assume they haven't this yet". Let's start assuming they do. Let's stop treating 5.10 as the "new shiny thing only the cool kids have".