Hi

The following code leads to a strange behavior.

First pressing "Calculate" button prints the expected result: Uw=2.6.

Then if I press "Characteristics" button and close the Characteristics window, pressing again "Calculate" button leads to Uw=0 for the same values of independent variables! I tend to conclude that $window{xAf} is somehow considered as a character...

Could somebody please tell me what I am doing wrong?

use strict; use warnings; use Tk; my $roomTl; my %window = (xAf=>0.20); my $mw = new MainWindow( ); $mw->Button( -text => "\n Characteristics \n", -command => \&roomSub, )->pack(-fill => "x"); $mw->Button( -text => "\n Calculate \n", -background => "red", -command => \&designSub, )->pack(-fill => "x"); MainLoop; sub roomSub { if (! Exists ($roomTl)) { $roomTl = $mw->Toplevel( ); $roomTl->Entry( -textvariable => \$window{xAf}, )->pack(-fill => 'x'); } else { $roomTl->deiconify(); $roomTl->raise(); } } sub designSub { my $Uf = 13; my $Uw = $window{xAf} * $Uf; print "Uf = $Uf \t xAf = $window{xAf} \t Uw = $Uw \n"; }

In reply to perl/Tk Problem with referenced variable in Entry by contact@solamen.fr

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.