Hi all

I am having trouble getting a subprocedure to work using parameter data passed 
with shift

Here is the calling routine. It's a snippet. All the modules are called properly

sub mainmenu
{
  my $self = shift;
  my $dbh = $self->param('mydbh');
  
  # Get the CGI query object so that you can use the CGI.pm modules.
  my $q = $self->query();

  # Setup the template to use for the output.
  my $template = $self->load_tmpl('test2.tmpl.htm');

  # call param to fill in the loop with the loop data by reference.
  $template->param(db_loop => \GetOfficers());
  # Output the template...
  $template->output;
}

And this is the sub Getofficers:

sub GetOfficers
{
  my $self = shift;
#  my $self = @_;
  my $dbh = $self->param('mydbh');
  # Get the CGI query object so that you can use the CGI.pm modules.
  my $q = $self->query();
  my $sqlstr = '';
  
    $sqlstr = <<SQLStmt;
    SELECT Name FROM qryOfficer;

SQLStmt
    #SELECT Family FROM tblOfficer;

  # Get the database connection then Prepare and Execute the SQL Statement
  my $sth = $dbh->prepare($sqlstr);
  $sth->execute()
    || die "Could not execute SQL Statement!!\n$sqlstr";

  # Setup the template to use for the output.
  my $template = $self->load_tmpl('test2.tmpl.htm');
  my @Officer;  # the loop data will be put in here for the html template.

  # Now get the table rows and send the list off to the HTML form.....
  while (my $row = $sth->fetchrow_hashref)
  {
    #set up the data in an array to give to the HTML template....
    my %line =
    ( 
      HTML_ProjectName => $row->{Name},
    );
    # put this row into the loop by reference             
    push(@Officer, \%line);
    
  }
  return @Officer
}

I get the following error:

Error executing run mode 'Mode_0': can't call method "param" on an undefined 
value at Test_code.pm line 284

Which is this line:

my $dbh = $self->param('mydbh');

So what is happening? How can I pass down the db stuff? I tried passing down 
$self from the main sub but it didn't work either

Any help would be appreciated.

Cheers

Mick Hawkes



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to