Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "1;" in a Perl source? [duplicate]

Possible Duplicate:
What does 1; mean in Perl?

I'm new to Perl and learning how to build a class with Perl.

As from this example: http://www.tutorialspoint.com/perl/perl_oo_perl.htm, I see a line which is written as "1;" just can't find information about this interesting line from perldoc.perl.org

Do you know what it is? And why is it there in the Perl source code?

like image 378
nicola Avatar asked Apr 03 '11 08:04

nicola


1 Answers

A module is normally a bunch of subroutine definitions, but it can also include code that is not in a subroutine (such as initialisation code). This code might fail, so Perl lets you indicate this by returning false whereupon Perl aborts with an error.

However, since the default return value is false, we must explicitly return true at the end of a module.

The perldocs have this to say:

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

like image 66
Wood Avatar answered Oct 06 '22 00:10

Wood