Versions:
   Perl 5.6.1
   DBI 1.28
   DBD::Oracle 1.06
   Tk 800.023

I'm trying to learn Tk and have it interact with a database but having problems passing variables:

use strict;
use Tk;
use DBI;
use DBD::Oracle;

my $main = MainWindow->new();

my $top = $main->Frame()->pack();

my $left = $top->Frame()->pack(-side=>'left');
my $id_lbl = $left->Label(-text=>'ID')->pack();
my $name_lbl = $left->Label(-text=>'NAME')->pack();

my $left2 = $top->Frame()->pack(-side=>'left');
my $id_txt = $left2->Label(-text=>"",-width=>12,-background=>'white')->pack();
my $name_txt = $left2->Label(-text=>"",-width=>32,-background=>'white')->pack();


my $mid = $main->Frame()->pack(-side=>'top');
my $right = $mid->Frame()->pack(-side=>'left');
my $ent = $right->Entry(-width=>8,-background=>'white')->pack(-side=>'left');
my $go = $right->Button(-text=>'Get Data',-command=>sub{compute($ent)})->pack(-side=>'top');


MainLoop();

sub compute {
    my $data_source = "DBI:Oracle:host=*****.****.***.***;sid=****";

    my $dbh = DBI->connect($data_source,"*************","**********")
    or die "Cannot connect to $data_source; $DBI::errstr\n";

my $sth = $dbh->prepare(qq(SELECT cuid, cuname
FROM fcustomer
WHERE cuid = ?)) or die "Cannot prepare query: $DBI::errstr\n";


$sth->execute($_[0]) or die "Cannot execute query: $DBI::errstr\n";

my @row = $sth->fetchrow_array;

    $id_txt->configure(-text=>$row[0]);
    $name_txt->configure(-text=>$row[1]);
    $sth->finish();
    $dbh->disconnect;
}

When I enter an id in the Entry widget and click on the button, I get the following error message:

Tk::Error: Can't bind a reference (Tk::Entry=HASH(0x26c9f24)) at tk_test4.pl line 88.
main::compute at tk_test4.pl like 38
main::__ANON__ at tk_test4.pl line 23
[\&main::__ANON__]
Tk callback for .frame1.frame.button
Tk::__ANON__ at H:/Perl/site/lib/Tk.pm line 228
Tk::Button::butUp at H:/Perl/site/lib/Tk/Button.pl line 111
(command bound to event)


I've tried to dereference $ent by sending $$ent but that didn't work either and gave me the error of "not a SCALAR reference". Any suggestions welcome.

-Mike


-- 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