Click here to get back home

Is a hash the best method to do this?

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Is a hash the best method to do this? vorticitywolfe 12-24-2007
Posted by vorticitywolfe on December 24, 2007, 1:23 pm
Please log in for more thread options
Hello,

I have a gui which reads a lot of data and fills in a table of entry
widgets with the updated values for certain variables. I want to make
it more dynamic and be able to creates x by y number of entry widgets
on the fly. Right now, I have a program that works, but I have
thousands of lines of repeated code and it just keeps getting more
difficult to keep track of everything, particularly when I want to
change one thing. I wrote a previous post about defining variables
within a for loop, which sounded good to me until I read some of the
other posts on why this is bad. Hashes seem like they would work for
this, but as a novice, it seems a little over my head on how to
accomplish this.

From here on, I think the code can be cleaned up and I should only
have to define it once while still maintaining the flexibility to add
more rows/columns. Is that possible?

# N ROWS
################################################
@stn=(0...N-1);

my $left2a = $top->Frame()->pack(-side=>'left',-pady=>2,-padx=>7);
# N Columns
################################################
my $z0=$left2a->Label(-text=>'Time (Z)',)->pack();
my $z1=$left2a->Entry(-justify=>'center',-background=>'light green',-
width=>5,-borderwidth=>2,-relief=>'sunken')->pack();
my $z2=$left2a->Entry(-justify=>'center',-background=>'light green',-
width=>5,-borderwidth=>2,-relief=>'sunken')->pack();
my $z3=$left2a->Entry(-justify=>'center',-background=>'light green',-
width=>5,-borderwidth=>2,-relief=>'sunken')->pack();
my $z4=$left2a->Entry(-justify=>'center',-background=>'light green',-
width=>5,-borderwidth=>2,-relief=>'sunken')->pack();
my $z5=$left2a->Entry(-justify=>'center',-background=>'light green',-
width=>5,-borderwidth=>2,-relief=>'sunken')->pack();
my $z6=$left2a->Entry(-justify=>'center',-background=>'light green',-
width=>5,-borderwidth=>2,-relief=>'sunken')->pack();
my $z7=$left2a->Entry(-justify=>'center',-background=>'light green',-
width=>5,-borderwidth=>2,-relief=>'sunken')->pack();




# FIRST STATION
################################################################
                if ($string =~/$stn[0]/){
                        if($string =~ m/\d\d(\d\d\d\d)Z/){#if($string =~ m/(\d\d\/d\d)/){
                                if (defined($1)) {
                                        $time=$1;
                                }

                        }else{
                                        $time="M";
                        }
                        $z1->delete('0.0','end');
                        $z1->insert('1.0',$time);
                }


I hope this is clear enough, if not feel free to ask. Any suggestion
is helpful.
Thanks,
Jonathan

Similar ThreadsPosted
Modules for hash functions? (ie, common algorithms for computing hash keys, not manipulating perl hashes) August 26, 2006, 7:08 pm
Hash July 14, 2006, 5:27 pm
What can you use to tie a hash of hashes to either dbm or ascii? December 2, 2007, 12:26 pm
Options for passing Hash to a subroutine. March 30, 2005, 7:39 pm
Announce: Set::Array, Set::Hash, Set::String - new maintainer January 8, 2005, 10:04 am
Bug with hash time & multilines in Config::IniFiles v2.38 ? January 26, 2005, 9:53 am
Sorting Hash of Hashes with HEAP module March 17, 2005, 2:56 pm
accessing a hash made by iCal::Parser February 6, 2006, 11:16 am
Error-flag references to non-existing hash elements? March 8, 2005, 1:08 pm
Devel::Cover failing with 'bizarre copy of hash in leave' error October 21, 2004, 2:09 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap