Welcome to the Monastery | |
PerlMonks |
Re: sub-routinesby jreades (Friar) |
on Nov 28, 2002 at 12:45 UTC ( [id://216293]=note: print w/replies, xml ) | Need Help?? |
The quick answer is that you only return $line and not the entire file, but there are some other significant issues with the code. You also reset the variable $line twice within the subroutine, and it's not scoped properly. Although you can sort of get away with what you're doing here (calling a file within a subroutine that isn't properly scoped to that subroutine), it's hard to read and prone to bugs. A better way to think about this is to address the fact that the subroutine operates on a single line at a time, and not the entire file. Don't shoehorn in the file operation as well since it doesn't make logical sense. Instead, pass the subroutine a line at a time since that is its logical 'scope' (as distinct from the lexcial scope).
I think that'll do it.
In Section
Seekers of Perl Wisdom
|
|