Gossamer Forum
Home : General : Perl Programming :

perl code question

Quote Reply
perl code question
what is the meaning of
exit;
next;
1;
at the end of some subroutine?
Quote Reply
Re: perl code question In reply to
The first two are commands, basically exit simply exits the program at that point in the program. It is often used when an error occurs, or if you need to stop output at a crucial moment.

"next" is used in iterations of loops, (foreach, for, while, etc.) When next is called, it causes the current iteration to stop and starts a new one. This can be useful if you need to skip to the next value of input in an array, etc.

"1;" is MOST often used in modules and libraries. ALL modules must return 1 as the last statement called from that module. Its an error checking feature of Perl. You can also use 1; as a return value for a subroutine, because a subroutine will always return the value of the last statement executed. This would be considered a messy coding practice, making readability confusing. It would be better to use: return 1;

Hope this helps.


------------------
Fred Hirsch
Web Consultant & Programmer
Quote Reply
Re: perl code question In reply to
Thanks a lot!