Perl seems to be killing my array whenever I read a file:
my @files = ("foo", "bar", "baz");
print "Files: " . join(" ", @files) . "\n";
foreach(@files) {
print "The file is $_\n";
func();
}
sub func {
open(READ, "< test.txt");
while(<READ>) {
}
close READ;
}
print "Files: " . join(" ", @files) . "\n";
produces:
Files: foo bar baz
The file is foo
The file is bar
The file is baz
Files:
but when I comment out func()
, it gives what I would've expected:
Files: foo bar baz
The file is foo
The file is bar
The file is baz
Files: foo bar baz
Any ideas why this might be happening?