[lug] variable scope in perl/Tk ?

Ralf Mattes rm at ns.aura.de
Thu Apr 13 14:10:28 MDT 2000


On Wed, 12 Apr 2000, arnie wrote:

> I have a pair of Radiobuttons I am using to set a variable named
> $mode...
> 
> $frame_1->Radiobutton(-text => "PRODUCTION",
>  -command => sub {
>   $mode = PRODUCTION;
> )->pack(-side => 'right');
> 
> 
> $frame_1->Radiobutton(-text => "TRAINING",
>  -value => "0",
>  -command => sub {
>   $mode = TRAINING;
> )->pack(-side => 'right');
> 
> 
> I later try to use the value in $mode like this:
> 
> 
> sub post_warning {
>   if ($checkbutton_CO_value == 1) {
>    `cp message/warn_template user_msg_{$MODE}_CO_warn`;
>   }
> }
> 
> 
> 
> When I run this the file I get is named user_msg_{}_CO_warn
> How can I get this file to end up with the name
> user_msg_PRODUCTION_CO_warn or user_msg_TRAINING_CO_warn ?
> 

If this is really the code you run the solution is simple:

> `cp message/warn_template user_msg_{$MODE}_CO_warn`;

< `cp message/warn_template user_msg_${mode}_CO_warn`;

(Assuming that $mode is a global variable. BTW, i would put
quotes arround TRAINING and PRODUCTION in your anonymous 
subroutines.

 Ralf

*-------------------------------------------------------------------*
|                                     |                             |==
| Ralf Mattes                         | ralf.mattes at pyramid.de      |==
| Programming, Administration         | rm at ns.aura.de               |==
|                                     |                             |==
*-------------------------------------------------------------------*==
   ====================================================================





More information about the LUG mailing list