Hi Monks. I'm a begginer.

I´m using Perl/Tk to make an small aplication... I have one line with two Entry fields and I need store each pair of entry in a hash pair key-value. Until this it's nice but user should can add new lines and for this I need store more hash pairs. How can I store new entries in hash?

My code:

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

Edit: g0n: code tags


In reply to 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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.