in reply to Re: Re: Hashes/Scalars and Memory Usage
in thread Hashes/Scalars and Memory Usage

In this case I would certainly use a hash. You say you have the above bit of code duplicated several times in your script? This is immediately a sign that your code can probably be re-worked to eliminate the duplication.
my @FIELDS = ( company_name => 'Company Name', company_addr => 'Company Address', ... ); for (my $i = 0; $i < @FIELDS; $i+=2) { my $field = $cgi->textfield( -name => $FIELDS[$i], -default => $tabdata->{CompanyInfo}->{$FIELDS[$i]}, -size => 30, ); $screen->AppendToSection('body', <<"EOF"); <tr> <td class='fieldname'>$FIELDS[$i+1]</td> <td class='fieldvalue'>$field</td> </tr> EOF }
If your code varies in more than this respect (e.g. size, the use of another hash key besides CompanyInfo, etc), you could re-structure the @FIELDS array something like this:
my @ARRAY = ( 'Company Name' => [ 'CompanyInfo' => 'company_name', 30 ], 'Company Address' => [ 'CompanyInfo' => 'company_addr', 60 ], ... );
Then adapt your code to follow suit..

Replies are listed 'Best First'.
Re: Re: Re: Re: Hashes/Scalars and Memory Usage
by EvilTypeGuy (Initiate) on Feb 10, 2001 at 02:14 UTC
    To quote something pinkyish: "Astounding Brain, how do you do it?" This is something i've done similarly other places before, and for some reason I had a brainfart and forgot I could do this. Thanks for reminding of something I shouldn't have forgotten to begin with :p This definitely cuts down on Code Bloat(TM), plus makes my code look 3r33t(TM)... Maybe you should author 3r33t perl tricks to live by...