Perl Question

Jamie McCarthy jamie at mccarthy.org
Mon Jan 5 14:25:19 EST 1998


Carol Lagundo wrote:

> Does anyone know how to write a Perl script that will take several small
> text files and consolidate them into one large file?  I have very little
> experience with Perl.  Any help would be greatly appreciated.  Thanks.

If you're on unix, you can do this without perl:

   $ cat file1 file2 file3 > newfile

Assuming you're not on unix, here's a perl solution.  (Before anyone
points out that this could be done much smaller:  this is without
command line switches or relying on pipe redirection, for maximum
compatibility with nonunix systems.  :-)

   #!/your/path/to/perl
   $out = pop @ARGV; open(OUT, ">$out");
   while (<>) { print OUT $_ }

Where "/your/path/to/perl" is whatever you normally put in the first
line, of course.  This can be invoked on just about any system, as:

   whatever_you_named_the_above_program file1 file2 file3 newfile

-- 
 Jamie McCarthy                 jamie at mccarthy.org
 homepage: http://www.absence.prismatix.com/jamie/
   fan of: http://www.nizkor.org/


More information about the Web4lib mailing list