webby01 has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: Merging two files and changing format
by choroba (Cardinal) on Oct 11, 2012 at 15:13 UTC
    You can read from both input files simlultaneously:
    #!/usr/bin/perl use warnings; use strict; open my $IN1, '<', 'infile_1' or die $!; open my $IN2, '<', 'infile_2' or die $!; open my $OUT, '>', 'test2' or die $!; while (my $in1 = <$IN1>) { chomp $in1; defined(my $in2 = <$IN2>) or die "file2 too short\n"; $in2 =~ s/\s//g; print {$OUT} join("\t", split /\s+/, $in1), "\t", join("\t", split + //, $in2), "\n"; } die "file1 too short\n" if <$IN2>; close $OUT;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      this code gives me a file with 805948 rows, when the desired amount of rows is 660918.

      i think the problem is that some entries are -- instead of, 'AA' for example in the case of missing data. Are there any modifications I can make to the code to remedy this? Thank you.

        Please, show an example of a pair of lines that is not processed correctly.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Merging two files and changing format
by BrowserUk (Patriarch) on Oct 11, 2012 at 15:53 UTC

    C:\test>head -3 1.dat 01 01 01 01 01 01 02 02 02 02 02 02 03 03 03 03 03 03 C:\test>head -3 2.dat A A A B B B C C C C:\test>perl -nle"printf "%s",join qq[\t],split(' ',$_),do{(my$t=<STDI +N>)=~tr/ //d;split'',$t};" <1.dat 2.dat A A A 0 1 0 1 0 1 + 0 1 0 1 0 1 B B B 0 2 0 2 0 2 + 0 2 0 2 0 2 C C C 0 3 0 3 0 3 + 0 3 0 3 0 3 D D D 0 4 0 4 0 4 + 0 4 0 4 0 4 ...

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong