Mike,<br><br>I spoke a bit too soon. Something strange is going on -- or maybe it's not so strange. If Fax.pm is called after require "./QuoteJoke.pl"; has already been called<br> my $string = &main::get_quote_joke();<br><br>works like a charm and "&get_quote_joke();" fails with udefined subroutine.<br><br>If on the other hand if Fax.pm is called from a program when <br><br>require "./QuoteJoke.pl"; has not been previously called then<br><br> my $string = &main::get_quote_joke(); <br><br>fails with undefined subroutine &main::get_quote_joke()<br><br>and &get_quote_joke(); works.<br><br>Any idea why this maybe the case?<br>
<br><br><br><b><i>Mike Fragassi <frag@ripco.com></i></b> wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> <br>On Fri, 28 Dec 2007, Richard Reina wrote:<br><br>> How can one properly declare another script's subroutine from within a <br>> Module.<br>><br>> I would like to be able to do this:<br>><br>> require "./QuoteJoke.pl";<br>> my $string = &get_quote_joke();<br>><br>> from a my home made perl module Fax.pm<br>><br>> without getting:<br>><br>> Undefined subroutine &Fax::get_quote_joke called at Fax.pm line 61<br><br>Inside Fax.pm, assuming that this module has the line 'package Fax;', <br>then calling any method 'foo' will be interpreted as a call to <br>&Fax::foo.<br><br>If a file (.pl or .pm) does not have a 'package' declaration, its <br>commands are in the package 'main' by default. If that's the case with <br>QuoteJoke.pl,
then inside of Fax.pm, calling '&main::get_quote_joke()' <br>should work. Otherwise, if there's a package, use that instead of <br>'main'.<br><br>> I know I am probably breaking some cardinal rule of perl but I can't <br>> figure it out.<br><br>You're not really breaking anything, or doing anything crazy; you just <br>need to prepend the package name where the method comes from, when <br>you're calling it from inside a different package.<br><br>-- Mike F.<br>_______________________________________________<br>Chicago-talk mailing list<br>Chicago-talk@pm.org<br>http://mail.pm.org/mailman/listinfo/chicago-talk<br></blockquote><br>