Michael Ragsdale wrote:

> 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');

Though this doesn't affest the compilation or running of your code, it does affect
people's willingness to help--can you see the difference between say this:
$left->Label(
and [big hint here] these:
-text=>"",-width=>12,-background=>'white' ?
Please make appropriate use of whitespace in your code.  It is fine to dereference
an element with an unbroken string.  That's because you are usually looking for
one thing, the element or function name at the end of the string.  Elements of a
list, operands of standard binary operators [including assignment], or other
constructs where the operator is not intended to glue tokens together, should
usally have some space around the operator.  :

-text => '', -width => 12, -background => 'white'


>
> 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');

I see here that you are handing your fictional tree-person as an argument to your
callback.

> ...

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

Okay, now.  What happened to Treebeard?  Generally, when you pass data to a
function, retreiving it from the parameter list should happen early on, lest it be
forgotten.  Try:
   my $entry_widget_ref = shift;
as the first line of this subroutine.  Then, before preparing the query:
   my $user_string = $entry_widget_ref->get;

>      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 = ?))

Is this where you are trying to use that value from the Entry widget?  If so,
don't do it.  Hand an SQL engine only queries that have been completed.
                                WHERE cuid = $user_string ))

That should get you started at least.  Please put some spaces around your binary
operators, and follow your arguments through into subroutines to ensure that they
get defined properly.

Hmmm, have you had any practice in passing parameters, and making and using
parameterized subroutines?  I know most people start out with ambitious projects,
but to make your project succeed, you may have to step back a few paces and
acquaint yourself with some language basics.  Both Tk and DBI are high-end
modules, that presume an understanding of programming essentials.  I'd recommend a
series of smaller projects, testing basic concepts such as argument passing and
use of references, before attempting to develop application software.

Joseph


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