Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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 tkprog.pl 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 http://perldoc.perl.org/functions/sort.html 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"; }

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re: Values changing by liverpole
in thread Values changing by Caito

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (None)
    As of 2024-04-25 04:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found