I wrote a super simple script:
#!/usr/bin/perl -w use strict; open (F, "<ids.txt") || die "fail: $!\n"; my @ids = <F>; foreach my $string (@ids) { chomp($string); print "$string\n"; } close F;
This produces the expected output of the entire contents of the ids.txt file:
Hi
world
this is
annoying
Source
the lines
Now I want to add a file extension: .txt for each line. This line should do the trick:
#!/usr/bin/perl -w use strict; open (F, "<ids.txt") || die "fail: $!\n"; my @ids = <F>; foreach my $string (@ids) { chomp($string); $string .= ".txt"; print "$string\n"; } close F;
But the result is as follows:
.txto
.txtd
.txte
.txtying
.txtcecode
Instead of adding ".txt" to my lines, the first 4 letters of my line will be replaced by ".txt". Since I want to check if any files exist, I need the full file name with the extension.
I tried chopping, chomp, replacing (s / \ n //), merging and whatever. But the result remains a replacement instead of adding.
Where is the mistake?
Ajin
source share