From: Peter Rabbitson <[EMAIL PROTECTED]> > For example transaction fee, fee assessment, discount rate for > all visa, master, discover, amex. Say we name the Input types > accordingly: > > 6_pct - discover discount rate > 6_tfee - discover transaction fee > 6_fa - discover fee assessment > 5_pct - master card discount rate > .... > you get the idea. Now I want to read them in the script: > > $pct{6} = $form->param('6_pct'); > $tfee{6} = $form->param('6_tfee'); > $fa{6} = $form->param('6_fa'); > $pct{5} = $form->param('5_pct'); > .... > Wow... what if I had 10 kinds of cards and 20 properties for each? > > However if I could define: > %cards = (4,"Visa", 5,"MasterCard", 6,"Discover", 3,"AmEx"); > @props = ("pct", "tfee", "fa"); > and than do: > foreach $c (keys (%cards)) { > foreach $p (@props) { > $($p){$c} = $form->param('($c)."_".($p)');
Change that to ${$p}{$c} = $form->param($c."_".$p); and it will be runnable (albait not perfect) code. > } > } It would still IMHO be much better to do something like: %cards = ( 4 => {name => 'Visa'}, 5 => {name => 'MasterCard'}, 6 => {name => 'Discover'}, 3 => {name => 'AmEx'}, ); foreach my $cardid (keys %cards) { foreach my $property (@props) { $data{$cardid}{$property} = $form->param($cardid."_".$property); } } This way you have just one variable holding all the data, not several separate variables. So you can pass the whole data between functions easily, you can keep several separate data structures holding different data ... It's probably not worth the effort to go rewrite the whole script, but believe me GLOBAL VARIABLES ARE BAD. And soft references are even worse. You may be able to keep track of everything if you are writing a single small script, but once you start on something bigger globals and soft references will surely bite you. You say "the code will instantly break if some doofus changes the names of the variables", yes that's quite possible. And the doofus may easily be you two months later, after you've forgotten the details of the implementation of this stuff. Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>