The following uses the <> operator to read all the files passed on the command line in a line at a time fashion. Each value is appended to a list in memory and then joined and printed when the internal file handle used by the diamond operator hits an end of file (see the description of eof in perlop for details).
#! /usr/bin/perl
use strict;
use warnings;
my @line;
while (<>) {
chomp;
push @line, "$_";
} continue {
if (eof) {
print join("\t", @line), "\n";
@line = ();
close ARGV;
}
}
Update: Simplified. No need for an array or any fancy joining!
while (<>) {
chomp;
if (eof) {print "$_\n"}
else {print "$_\t"}
}
The order that the files are appended is taken from the order in which they are listed in @ARGV. This can be sorted before the files are processed.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.