You create a lexical variable called $file that exists within the scope of your while loop. Once the while loop terminates, that scope disappears and the that variable ceases to exist. You then try to access another variable called $file. As there is no lexical variable of that name in existance, Perl assumes that it is a package variable. But as you have "use strict" turned on, you need to either predeclare or explicitly name any package variables that you use. As you have done neither of these two things, you get the error you've shown us.
The solution to your problem would be to create the lexical variable $file outside of the loop, so that it doesn't just exist within that scope.
--"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re: Passing value outside of loop
by davorg
in thread Passing value outside of loop
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |