Perl seems to kill 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";
gives:
Files: foo bar baz The file is foo The file is bar The file is baz Files:
but when I comment on func() , it gives what I would expect:
Files: foo bar baz The file is foo The file is bar The file is baz Files: foo bar baz
Any ideas why this could be happening?
source share