adding a filename into a data file

Benjamin Martin benjamin.martin at
Mon Nov 5 06:33:11 PST 2012

On 05/11/12 14:13, Matt Croft wrote:
> Is this possible in perl?

Something like this:

#!/usr/bin/env perl

use strict;
use warnings;
use autodie;

my $base_dir = "/home/person";   # as base dir to read/write file to/from
my @files = qw/file1.txt file2.txt/;  # the files to read and combine

open $new_fh, ">", "$base_dir/NEWFILE.txt"; # open the master file to
receive all files content
foreach my $f (@files) {

   my $fh
   open $fh, "<", "$base_dir/$f";
   while(<$fh>) {
     print $new_fh "$f $_";
   close $fh;

close $fh2;

This email, its content and any files transmitted with it are intended solely for the addressee(s) and may be legally privileged and/or confidential. If you are not the intended recipient, you may not divulge any of its contents to anyone and should delete the email and contact the sender on the telephone number shown above or via return email. Messages sent via this medium may be subject to delays, non-delivery and unauthorised alteration.  This email has been prepared using information believed by the author to be reliable and accurate, but neither TwentyCi Limited, nor any of its subsidiaries or associates makes any warranty as to its accuracy or completeness.  Any opinions or recommendations expressed herein are solely those of the author. TwentyCi Limited is a company registered in England, No.06943607. The registered office address is: 6 Whittle Court Knowlhill Milton Keynes MK5 8FT

More information about the MiltonKeynes-pm mailing list