[EMAIL PROTECTED] wrote:
> Hi Coders,
> I have the following piece of code:
> 
> $menub = $mw->Menubutton(-text => "Edit",
>   -menuitems => [["command" => "Parameters", -command =>sub {
> $param_win = MainWindow ->new; $param_win ->title("Annealing
> parameters"); $param_win ->Label(-text => "Algorithm :
> Simulated Annealing",
>   -background => "blue",-foreground => "white", -relief =>
> "raised")->pack(); $param_win ->Label(-text => "Initial Temperature:",
>   -foreground => "Blue")->pack();
> $text1 = $param_win->Text(-width => '10', -height =>
> '1')->pack; $param_win ->Label(-text => "Final Temperature:",
>   -foreground => "Blue")->pack();
> $text2 = $param_win->Text(-width => '10', -height =>
> '1')->pack; $param_win ->Label(-text => "Inner Loop Criterion:",
>   -foreground => "Blue")->pack();
> $text3 = $param_win->Text(-width => '10', -height =>
> '1')->pack; $button = $param_win->Button(-activebackground => 'blue',
>   -activeforeground => 'yellow', -text => "Save",
>   -command => sub {Echo ($entry, $text1,$text2,
> $text3)})->pack(); }]])->place(-x => '30', -y => '0');
> 
> sub Echo {
>       ($widget, $text1, $text2, $text3) = @_;
>       $initial_anneal_temp = $text1->Contents();
>       $final_anneal_temp = $text2->Contents();
>       $inner_loop_criteria = $text3->Contents();
>       print "$initial_anneal_temp $final_anneal_temp
> $inner_loop_criteria\n"; }
> 
> under main.
> 
> I also have this code under main::
> 
> if ($initial_anneal_temp != "0"){
>   $init_temp = $initial_anneal_temp;
> } else {
>   $init_temp = 400000;
> }
> if ($final_anneal_temp != "0"){
>   $final_temp = $final_anneal_temp;
> } else {
>   $final_temp = 0.10;
> }
> if ($inner_loop_criteria != "0"){
>   $ni = $inner_loop_criteria;
> } else {
>   $ni = 30;
> }
> $temp = $init_temp;
> 
> So there are entries made into Text widget, my program should
> run with whatever is there in those entries.
> 
> Unfortunately, my program is always going with defaults.
> I do not know why?
> Can you please help. I think my understanding of local/global
> perl variables is skewed.

A few comments about your code. You don't appear to be using 'use
strict;' and 'use warnings;', and the parameters to the only subrouting
that you show do not have local scope. Some of your code seems to have
been mangle, possibly because the line length was too long. If you warp
long lines at sensible places this may not happen. Also it is generally
better to post a short working script that demonstrates you problem
rather than cut & paste some small part of a much larger program.

You may be right about your understanding of variable scope, in which
case the following article, in addition to the documentation supplied
with Perl, may be of help. It is called "Coping with Scoping"
(http://perl.plover.com/FAQs/Namespaces.html).

HTH

-- 
Brian Raven
 


-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary 
companies.
-----------------------------------------------------------------------


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to