Okay, I give. You guys convince me. Thanks.
FWIW my problem was that end user (a comittee, alas) could
not make up its mind what all to put into a Perl/Tk form by
way of entry widgets. I was sick and tired of re-writing
them over every time. So I wanted a way to auto-instantiate
them from a list.
You convince me to go with hashes, as below. Now I can
re-write the rest of the code to test for definedness of
entry box data by row (if hash exists) and by column (if
value exists). If I am careful, then when next they change
their collective mindes, I can just change the hash values
and the rest should track.
This works for me on both Win2K and NetBSD, and time presses
so I am going with it. Pray this method offends no-one.
#!c:\perl\bin\perl.exe
#!/usr/pkg/bin/perl
use Tk;
use strict;
use vars qw/$mw $col %row_1 %row_2 %row_3/;
# The main window.
$mw = MainWindow->new(-title=>'Fatigue Tracking Sheet');
%row_1 = (
parent_frame => $mw,
label_width => 12, entry_width => 10,
label_1 => 'Alpha 1',
label_2 => 'Bravo 2',
);
%row_2 = (
parent_frame => $mw,
label_width => 12, entry_width => 10,
label_1 => 'Charlie 3',
label_2 => 'Delta 4',
label_3 => 'Echo 5',
label_4 => 'Foxtrot 6',
);
%row_3 = (
parent_frame => $mw,
label_width => 12, entry_width => 10,
label_1 => 'Hotel 7',
label_2 => 'India 8',
label_3 => 'Juliet 9',
label_4 => 'Kilo A',
);
sub mk_entrybox_row {
my ($row_ref,) = @_;
$$row_ref{'row_frame'} = $$row_ref{'parent_frame'}->Frame(
-relief=>'flat',
-borderwidth=>5);
for ($col = 1; $col < 9; $col++){
last unless (defined($$row_ref{"label_$col"}));
$$row_ref{"label_$col"} = $$row_ref{'row_frame'}->Label(
-width=>$$row_ref{"label_width"},
-text=> $$row_ref{"label_$col"});
$$row_ref{"entry_$col"} = $$row_ref{'row_frame'}->Label(
-width=>$$row_ref{"entry_width"},
-textvariable=>\$$row_ref{"textvar_$col"},-font =>'courier',
-background=>"white",-foreground=>'blue'); }
for ($col = 1; $col < 9; $col++){
last unless (defined($$row_ref{"label_$col"}));
$$row_ref{"label_$col"}->pack(-side=>'left');
$$row_ref{"entry_$col"}->pack(-side=>'left',-expand=>1,-fill=>'x');
}
$$row_ref{"row_frame"}->pack(-side=>'top',-expand=>0,-fill=>'x');
}
mk_entrybox_row(\%row_1);
mk_entrybox_row(\%row_2);
mk_entrybox_row(\%row_3);
# Backup results and quit program.
sub quit_MainLoop {
$mw->destroy() if Tk::Exists($mw);
}
MainLoop;
In reply to Re: create arbitrarily named scalars
by aplonis
in thread create arbitrarily named scalars
by aplonis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |