Umar Goldeli wrote:

> Greetings,
>
> Quite simply put - I have a little library of commonly used subs which I
> would like to require at the top of each page.. so I have:
>
> [-
>         use POSIX qw(ctime);
>
>         require "/opt/sage/lib/sagelib.pl";
>
>         $rv = selectall_dialin_account( $fdat{directory_id} );
> -]
>
> In on a page ( the fdat stuff is defined and all is well) - in sagelib, I
> have:
>
> sub selectall_dialin_account {
>
>         use DBI;
>
>         my ( $directory_id ) = @_;
>
>         $sage_dbh = DBI->connect( "DBI:Pg:dbname=sage;host=localhost",
> username, password ) or die "Error:" . $DBI::errstr . "\n";
>
>         $sth = $sage_dbh->prepare("select
> 
>directory_id,username,password,encryptedpassword,account_type,checkattr,replyattr,created_by,record_created,record_modified
> from dialin_account_data where directory_id='$directory_id'") or die
> "Error:" . $DBI::errstr . "\n";
>
>         $numrows = $sth->execute or die "Error:" . $DBI::errstr . "\n";
>
>         if ( $numrows > 0 ) {
>                 return $sth;
>         }
>         else {
>                 return;
>         }
>
> 1;
>
> In theory this should happily work right? I.e. a non-embperl script from
> the command-line - the above happily returns a ref...
>
> Although using a browser etc - it keeps whinging at me:
>
> Error in Perl code: Undefined subroutine
> &HTML::Embperl::DOC::_1::selectall_dialin_account called at
> /opt/apache/htdocs/admin/services/dialin/select.epl line 14.
>
> Any help would be copiously appreciated. :)
>
> //umar.

Umar,

Try 'do' instead of 'require'.  Has something to do with the namespace in which 
Embperl runs required files.  Another option
(better?) is to make the file you are requiring into a module (package) and then use 
'use' instead 'require'.

[-
        use POSIX qw(ctime);

        do "/opt/sage/lib/sagelib.pl";

        $rv = selectall_dialin_account( $fdat{directory_id} );
-]

Gerald,

Is my understanding correct in that the required files subs go out of scope as soon as 
the required file is done compling?  I
am not sure if this is how it is supposed to work so I am not sure if it a bug or 
feature, but I have been using 'do' as a work
around for the last 1.5+ years.

Aaron Johnson



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to