jalopez453 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to add the filename to the end of each line in my files. I tried a few solutions but none seem to work and this is what I have. I am not sure what I am missing or what is wrong.
#!/usr/bin/perl -w use strict; use warnings; use Text::ParseWords; opendir IN, 'Master'; my @in = grep { /\.txt$/ } readdir IN; # read all file names form dir +except names started with dot closedir IN; for my $in (@in) { open IN, '<', "Master/$in" || next; open OUT, '>', "Update/$in" || die "can't open file Update/$in"; my @file = @in while (my $file = <IN>) { my $line = $_; $updateline = $line . $file; print OUT "$updateline"; } close OUT; close IN; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Adding Filename to the end of each line
by haukex (Archbishop) on Apr 09, 2021 at 19:45 UTC | |
by jalopez453 (Acolyte) on Apr 09, 2021 at 20:57 UTC |