what is purpose of 1; at end of scripts

Discussion in 'Perl Misc' started by Danny, May 1, 2004.

  1. Danny

    Danny Guest

    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
     
    Danny, May 1, 2004
    #1
    1. Advertisements

  2. Danny <> wrote:

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


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, May 1, 2004
    #2
    1. Advertisements

  3. Danny wrote:

    > 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
     
    Gregory Toomey, May 1, 2004
    #3
  4. Danny

    Sam Holden Guest

    On Sat, 01 May 2004 15:19:16 +1000, Gregory Toomey <> wrote:
    > Danny wrote:
    >
    >> 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.


    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.

    --
    Sam Holden
     
    Sam Holden, May 1, 2004
    #4
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neo Geshel
    Replies:
    2
    Views:
    4,302
    Versteijn
    Aug 18, 2004
  2. William
    Replies:
    2
    Views:
    2,089
    Kevin Spencer
    Jun 1, 2005
  3. Replies:
    0
    Views:
    452
  4. Jan Danielsson
    Replies:
    8
    Views:
    903
    Mike Meyer
    Jul 22, 2005
  5. davidj411
    Replies:
    0
    Views:
    781
    davidj411
    Jun 27, 2008
  6. J
    Replies:
    1
    Views:
    551
    Martin P. Hellwig
    Apr 1, 2010
  7. No Where

    Function def at end of scripts

    No Where, Dec 12, 2008, in forum: Ruby
    Replies:
    10
    Views:
    336
    David A. Black
    Dec 15, 2008
  8. Replies:
    13
    Views:
    793
    Anno Siegel
    Sep 10, 2007
Loading...