in reply to problems returning from recursive subroutine
The DIR handle is GLOBAL. Therefore the recursive call clobbers (overwrites) the "parent"'s dirhandle so when the call returns the dirhandle is at the end of the list and therefore cannot return anything.
You have to add
into the subroutine, above the opendir or use a lexical dirhandle:local *DIR;
This syntax will not work in older Perls! You may need to add use FileHandle; and declare the $DIR above the opendir like this:sub lc_filenames{ my($dir)=@_; $dir||="."; opendir my $DIR, $dir; while(defined(my $file=readdir $DIR)){ ...
my $DIR; opendir $DIR, $dir;
Another nit. You do not close the dirhandle! You should!
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature
|
|---|