What is 1;

A

Alan Mead

What does the
1;
line of a perl script do?

Returns 1 which is a true value. It's the standard way of ending a
module. Try '0' or '' or undef... see what you get.

-Alan
 
A

Arndt Jonasson

What does the
1;
line of a perl script do?

See perldoc -f require:

"Note that the file will not be included twice under the same specified
name. 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 "C<1;>" unless you're sure it'll return TRUE
otherwise."
 
J

Josef Moellers

Ian said:
Hi all;

What does the
1;
line of a perl script do?

It signals successfull initialization of this script to the use-ing or
require-ing module/program.
 
T

Tad McClellan

Ian Pellew said:
What does the
1;
line of a perl script do?


Not much.

(the answer would be different if you had asked about a library or
a module rather than about a "script".
)
 
C

Christopher Nehren

nothing....it generates code, but serves no purpose....it is the smallest
and simplest progrma you could write....

Uhm, what? It's the traditional last line of a module or other simlarly
included file placed at the end of said file to ensure that the module's
code returns a true value to the require() (and thus use()) call. Note
that other values which return true are also acceptable.
not sure under what context you came across that line of code, but other
that the use below, i know of no other purpose it would be used for...."as
you typed it"

Probably at the end of a module or similarly included file. :) If you
know of no other purpose, then you really should read 'perldoc -f
require' and perldoc perlmod.
perl -MNet::pOP3 -e 1

Actually, you could do:
perl -MNet::pOP3

which executes

use Net::pOP3 (); .
 
S

Sherm Pendley

daniel said:
it generates code, but serves no purpose

Daniel, several people have already pointed out that it does have a
purpose, and what that purpose is. Can't you read?

sherm--
 
K

KKramsch

The use of 1 (or any other Perl true value) at the end of a module
(which many responders have already mentioned) is the only documented
use I know of such a line I know of, but in my code there many such
lines strewn about all over the place, left behind from debugging
sessions. The reason is that when I run a program in the Perl
debugger quite often it happens that even when I issue a debugger
command such as "c 50" the debugger will advance the program up to
line 50, but instead of stopping, it executes line 50 and proceeds
past it without stopping. I've never understood why this is, but
I've found that if I insert a line such as

1;

right before (the former) line 50, then "c 50" does bring the
program up to line 50 (i.e. the new "1;" line) and no further, as
desired. Klugey and clueless but functional. If there's a more
civilized way to deal with this situation I'd love to hear about
it.

Karl
 
M

Mark Bole

KKramsch said:
The use of 1 (or any other Perl true value)[..]
The reason is that when I run a program in the Perl
debugger quite often it happens that even when I issue a debugger
command such as "c 50" the debugger will advance the program up to
line 50, but instead of stopping, it executes line 50 and proceeds
past it without stopping. I've never understood why this is, but
I've found that if I insert a line such as

1;

right before (the former) line 50, then "c 50" does bring the
program up to line 50 (i.e. the new "1;" line) and no further, as
desired. Klugey and clueless but functional. If there's a more
civilized way to deal with this situation I'd love to hear about
it.

Karl

Hmm, I've never had this experience, even since version 4. The line
referenced by "c" in debugger has to be executable, no?

-mark bole
 

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

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top