PDA

View Full Version : Does the line 'exit;' have to be the last line in every Perl script


crmpicco
11-14-2006, 12:43 PM
exit;



Does the line 'exit;' have to be the last line in every Perl script?

LucyLocket
11-14-2006, 01:09 PM
No it doesn't. At least i've never put exit at the bottom of my perl scripts and they seems to work fine. The only line that must be there that I know of is #!/usr/bin/perl and that's always the very first line of your script. I'm only a newbie to perl though so I could of gotten it wrong. Please feel free to correct me if you know otherwise.

I hope that helps.

miller
11-14-2006, 08:14 PM
Does the line 'exit;' have to be the last line in every Perl script?


No. In fact, it is a better standard to always end every perl script with a "1;". This is so if you choose to use or require this script from another location, it will be sure to return a true in the last statement.

As quoted from: http://perldoc.perl.org/functions/require.html


The file must return true as the last statement to indicate successful execution of any initialization code, so it's customary to end such a file with 1; unless you're sure it'll return true otherwise. But it's better just to put the 1; , in case you add more statements.

crmpicco
11-24-2006, 04:29 PM
thanks for those comments, the reason i was asking was because I have seen alot of code with 'exit;' as the last line in the code........