Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Values changing

by liverpole (Monsignor)
on May 12, 2010 at 22:39 UTC ( #839751=note: print w/replies, xml ) Need Help??

in reply to Values changing

Hi Caito,

First, please format your question putting tags <code> and </code> around your code.  Otherwise it's very difficult to read.

Secondly, try putting:

use strict; use warnings;
at the beginning of your program.  Once you've fixed the errors that it gives you, you may notice that when you try to print the value of $i in the subroutine print_seq that its value is undefined:
Global symbol "$i" requires explicit package name at line 55 +.

That's because in the subroutine makeline() you are making $i lexically-scoped:

sub makeline { my $i; my $j; ... }
so you won't be able to see the value of that variable $i.  To make $i (or other variables) global, just defined them at the top of your program.

Another thing -- you shouldn't be using the variables $a and $b; they have special meaning in a Perl script (they are used for sorting -- see for information).

You're not using the values returned from makeline, nor are you using the values $i and $j anywhere (except that you're assigning them in one place each).

One other problem you have is that when you create the Scrolled 'Entry' widget, there's nothing in them yet.  So that's not the time to be fetching the contents.  You may want to keep those Entry widgets in a global array, and create another subroutine (executable via a new button) to grab the values of all the Entry widgets when you're ready to use them.

That's just a start ... please try fixing the formatting of your post, and give more explicit details about what you're trying to do, and what's going wrong, and we'l try to help you out.

For reference, here's what I think you should have for code so far:

#!usr/bin/perl -w # Libraries use strict; use warnings; use Tk; # Globals go here my %hash; my $i; my $j; # Main program my $mw = MainWindow->new(-title => "mkFast-A"); my $msgi = $mw->Label(-text => 'Making Easy things Easy', -relief => ' +groove'); $msgi->pack(-side =>'top'); my $button = $mw -> Button(-text=> '+', -command =>\&makeline); $button->pack(-side=>'bottom', -anchor=>'w'); my $but = $mw ->Button(-text=>'hash', -command =>\&print_hash); $but->pack(-side => 'bottom', -anchor =>'e'); my $but2 =$mw ->Button(-text=>'print', -command =>\&print_seq); $but2->pack(-side => 'bottom', -anchor =>'e'); # This section isn't doing anything useful # my $x = $$a; # my $y = $$b; # $hash{$x} = $y; # print (($x, $y) = each %hash); MainLoop(); sub makeline { my $Seqname = $mw-> Scrolled ('Entry', -scrollbars =>'os'); $Seqname->pack(-side=> 'left'); $i = $Seqname->get(); print "i is $i\n"; my $Sequence = $mw -> Scrolled ('Entry', -scrollbars =>'os'); $Sequence->pack(-side=>'right'); $j = $Sequence->get(); } sub print_hash { my ($key, $value); while (($key, $value) = each %hash) { print "$key => $value\n"; } } sub print_seq { print "$i"; }


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://839751]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2017-07-22 05:56 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (337 votes). Check out past polls.