what is purpose of 1; at end of scripts

D

Danny

I notice a lot of scripts that have a 1; at the bottom.
I am new to perl and trying to understand.

Usually at bottom of scripts that do something but do not print to a web
page or print this 1;

Thanks in advance
 
T

Tad McClellan

Danny said:
I notice a lot of scripts that have a 1; at the bottom.


It is not needed in programs, it is needed in libraries.

Is that where you saw them?

I am new to perl and trying to understand.


perldoc -f require


... 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.

Usually at bottom of scripts that do something but do not print to a web
page or print this 1;
^^^^^^^^^^^^

Oh. You must be talking about something else then...

.... can't tell what else unless you show us the code you are asking about.
 
G

Gregory Toomey

Danny said:
I notice a lot of scripts that have a 1; at the bottom.
I am new to perl and trying to understand.

Usually at bottom of scripts that do something but do not print to a web
page or print this 1;

Thanks in advance

Basicly, the last "executed statement" of a script should evaluate to true,
ie 1.

gtoomey
 
S

Sam Holden

Basicly, the last "executed statement" of a script should evaluate to true,
ie 1.

Why?

That is the case for a module or a library, since otherwise it won't work,
but for a script it makes no difference at all what the result of the last
executed statement was.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top