That code will in fact only cat the first line of file x and the first line of file y.

I wouldn't even use perl for this, but if you must:

#!/usr/bin/perl -w use strict; my ($string1, $string2); # read files in chunks instead of lines # remove if you realy want to read textfiles # line by line local $/ = \32768; # "block size" open (FILE1, "< x") || die "Cannot open file : $!"; open (FILE2, "< y") || die "Cannot open file : $!"; open (FILE3, "> z") || die "Cannot open file : $!"; # set binmode, so binary files don't get messed # up on systems with text/binary mode files # (like windows or MS-DOS) binmode (FILE1); binmode (FILE2); binmode (FILE3); print FILE3 <FILE1>,<FILE2> or die "Error concatenating: $!"; close FILE1 or die "Error closing x: $!"; close FILE2 or die "Error closing y: $!"; close FILE3 or die "Error closing z: $!";

update: fixed copy/paste error


In reply to Re: Answer: How do I join two files? by Joost
in thread How do I join two files side by side? by esther

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.