Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: A simple example OO script for total beginners

by ajdelore (Pilgrim)
on Sep 05, 2003 at 15:48 UTC ( #289248=note: print w/ replies, xml ) Need Help??


in reply to A simple example OO script for total beginners

1; # this 1; is neccessary for our class to work

Although this is true, I think that it would be more instructive to indicate what the 1; statement does, and why it is neccessary for the package to work.

The module has to return something to indicate success ie. a non-zero/null value. Someone new to the language might not know that by default perl will return the value of last statement. Perhaps you should use an explicit return statement, something like:

return 1; # let program know package has successfully compiled

Rather than just mentioning that there are other tutorials available, it would also be useful to link to some of them from this post.

</ajdelore>


Comment on Re: A simple example OO script for total beginners
Select or Download Code
Re: Re: A simple example OO script for total beginners
by nothingmuch (Priest) on Dec 30, 2003 at 01:29 UTC
    The module has to return something to indicate success

    I'd like to clarify. This is indeed not necessary for the class to work, but for perl to assume the inclusion of a file went well. When you do, use or require a file containing perl code, the value it returns to the caller is used to indicate proper loading, execution, or whatever the role of that code was. It is customary to end any perl code, especially that which is not a script pe se in a simple

    1;

    because this is not erroneous as using return is when there's nothing to return to (like in a simple script file), but does return truth when truth is needed, because in Perl the last value evaluated in some scope which returns (file, subroutine), is the return value.

    In short, it's not necessary for the class to work, but it is necessary if the module which contains the class will be loaded via an external file inclusion, instead of being supplied in the same file.

    -nuffin
    zz zZ Z Z #!perl
Re^2: A simple example OO script for total beginners
by shobhit (Sexton) on Apr 27, 2007 at 19:53 UTC
    An excellent article which got me started with OOP in Perl. This is exactly the kind of thing I was looking for.
    However, I would like to point out something. The
    1;
    at the end is not entirely necessary. We can just as well use,
    our @ISA=qw/Exporter/;
    Which I guess is a better way of telling the world, that you may import this package/class in your own scripts.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://289248]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2014-12-26 14:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls