dopey has asked for the wisdom of the Perl Monks concerning the following question:

I am using Tk to do GUI programing. Is there any way to create variables on the fly? Such as:
foreach $INFO (qw/BUTTON1 BUTTON2 BUTTON3/){ $INFO = $mainwindow->Button(-text => $INFO)->pack(); }
I just too lazy to write everything out. Thanks for your help!

Replies are listed 'Best First'.
Re: Creating Variables On The Fly
by Aristotle (Chancellor) on Jan 18, 2003 at 17:47 UTC
    my %button; for my $label (qw/BUTTON1 BUTTON2 BUTTON3/){ $button{$label} = $mainwindow->Button(-text => $label)->pack(); }
    Please make sure to Dominus' archived newsposts, part one, two and three on Why it's stupid to 'use a variable as a variable name'. Also, I suggest you make use strict; use warnings; a habit.

    Makeshifts last the longest.