Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Trying to load other perl scripts use() or require()

by Anonymous Monk
on Jul 21, 2002 at 04:47 UTC ( [id://183773]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

ok, I have a script called cart.pm that just has subroutines, but whenever I try to load I get an error
cart.pm did not return a true value at /home/dtdynoco/public_html/admi +n1130/admin.cgi line 12.
and my code..
require "cart.pm";

Replies are listed 'Best First'.
Re: Trying to load other perl scripts use() or require()
by dpuu (Chaplain) on Jul 21, 2002 at 04:58 UTC
    Add a line to the end of cart.pm that returns a true value. Traditionally:
    1;
    (that's a number, one). --Dave.
Re: Trying to load other perl scripts use() or require()
by gav^ (Curate) on Jul 21, 2002 at 04:59 UTC
    Make sure your module returns a true value. The last line should be something like: 1;

    gav^

      The value of any block in Perl is the result of the last statement in that block. If a block is a subroutine, then the result of the subroutine is the result of the block. You can use a "return" statement to exit the sub before the end; and at the end of the sub to be explicit about your intent. Modules are blocks. (Strangely, this doesn't apply to scripts: you have to use exit($value) to return a value from a script.) --Dave.
      ty I dont remeber reading this in my book. so 1 is just like return(1);
Re: Trying to load other perl scripts use() or require()
by mitd (Curate) on Jul 21, 2002 at 05:09 UTC
    Is it just me or /home/dtdynoco showing up in alot of ?? lately. :)

    append:

    1;

    to the end of cart.pm.

    Then go directly to perlmod do not pass go and read why.

    mitd-Made in the Dark
    'Interactive! Paper tape is interactive!
    If you don't believe me I can show you my paper cut scars!'

Re: Trying to load other perl scripts use() or require()
by FamousLongAgo (Friar) on Jul 21, 2002 at 05:47 UTC
    One of the many nice things to look forward to in Perl 6 is that this bit of cruft will go away.

    I've found that using h2xs to auto-generate modules is a good way to avoid omissions like this, and put in stub documentation, too.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://183773]
Approved by gav^
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-25 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found