>
>ok, so the routine is in main:: namespace?

Is it?  Does require put its arguments into the namespace from which it was 
called?

> > use NYT::Cnxdb;
> > my $cnxdb =
> > Cnxdb->new($conf{cnxdbUser},$conf{cnxdbPort},$conf{cnxdbTimeout});
> > die("Unable to connect to database: " . $cnxdb->getlasterror())
> >     unless $cnxdb->getok();a
> > #cnxdb is the object in question.  It is in the main package of the
> > module file
>
>You say "main package"....
>Is there a package statement in the file?
>It's a my() variable, but if it's a reference to some dataspace, then
>returning the reference makes the dataspace accessible through the
>reference.....
There are several package statements in the file, but not one to declare 
main.  I thought this was the default if no other package has been 
declare.  sub new_request_form lives in a separate namespace, allocated by 
a package declaration.

>aha?
>$cnxdb is a my() variable created in another function. It doesn't exist
>here unless it was passed in, which it doesn't look like it was.
>Does this file also have a "use strict;"?

This is curious because, as you can see in the code I sent (see below)  I 
use the $cnxdb object in this namespace without having passed it in.  The 
only place it is declared is as a lexical in the main::namespace of the 
same file.  This subroutine lives in the  file in which the object was 
created.  I

  my $class = shift;
    my $query;
    my @values;
    if ($class eq "BugTrack") {
         $query =<<EoQ;
         select DISTINCT ED_LASTNAME,ED_FIRSTNAME,ED_EMPLOYEEID from 
NYT_EMPLOYEE_DIR
         where ED_LOCATIONID = 1 and ED_EMP_STATUS <> 2
         order by ED_LASTNAME
EoQ
    $query =~ s#\s+# #g;
    (my $status,my $error, @values) = $cnxdb->execute("$query");
#this attempt to access $cnxdb object works, though it was never passed to 
the subroutine
    } else {
         my %responsibility = (
            'DBTrack' => 10,
            'SysTrack' => 9,
            'DevTrack' => 8,
         );
    @values = &select_people($cnxdb,$responsibility{$class});
#this attempt to pass cnxdb does not work
}
[snip]

> > And in the other file (request_sub.lib):
> >
> > sub select_people {
> >    my ($cnxdb,$responsibility) = @_;  #lexical copies of parameters
>
>Here you passed it in, so if you had it to pass, I think it'd work. =o)

So why is it that I can use an object in a namespace in which it was not 
declared, but cannot pass the same object from there?

thanks again
Peter Cline
Inet Developer
New York Times Digital

Reply via email to