Problems? Is your data what you think it is? | |
PerlMonks |
Exiting subroutine via next (that old chestnut)by why_bird (Pilgrim) |
on Mar 04, 2008 at 16:52 UTC ( [id://671926]=perlquestion: print w/replies, xml ) | Need Help?? |
why_bird has asked for the wisdom of the Perl Monks concerning the following question: Hi all This post is vaguely relevant to what I want to ask. As far as I can tell, the problem with exiting from a sub via next is that it performs the next iteration of any loop from within which it was called. However, that's the intention of my subroutine:
This seems to happily remove commented lines from the file I'm reading in (assuming comments are perl like) and then throws away the line if the whole line is empty (i.e. comments at the start of a line, or competely blank lines) by calling the next iteration of the while $temp=<INPUT> loop. Otherwise it passes the de-commented line through the rest of the script. However, although it appears to work happily, it throws an Exiting subroutine via next at xxx.pm line yy, <INPUT> line zz. error (and there's quite a lot of those so it's quite annoying!) The only other way I could see to do it would be to get &RemoveComments() to return a variable, say '$empty', and then have the main code evaluate this and decide whether to do a 'next' or not:
which just seems more messy to me, and more annoying to have to write an extra if(){} in every place that I just had to write &RemoveComments before. a)are my statements correct and/or b) am I missing a better way to do this or c) is my code happily working away nicely by accident..? thanks :)Those are my principles. If you don't like them I have others. -- Groucho Marx .......
Back to
Seekers of Perl Wisdom
|
|