You can't just use variables as part of other variables. And "T$iT.txt" searches for the variable $iT, and can't find it.
You can do this instead:
# always start your scripts with these two lines... use strict; use warnings; # and declare your variables foreach my $i (2 .. 4) { my $filename = 'T' . $i . 'T.txt'; open (my $file, $filename) or die "Can't open '$filename': $!"; my @a = <$file>; print @a; close $file; }
In reply to Re: Using a loop to process multiple files
by moritz
in thread Using a loop to process multiple files
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |