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

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.