I would like to substitute the hash name with
You don't have a hash name - which would mean you had named hashes - but hash keys in your array of anonymous hashes. If you change the key and reference that changed key, there's no value behind it - the value you are trying to acces is bound to the old (unchanged) key. To change a key, you have to copy over the value the old key is pointing at into the slot pointed at by the new key:
my $i = 1; $varname = "_address" . $i; $customer->[0]{$varname} = $customer->[0]{'_address'}; print "Customer Address", $customer->[0]{$varname};
But...
$customer->[0]{_address1} $customer->[0]{_address2}
whenever there are keys with a number attached, that cries for a revision of the data structure: store an anonymous array as the value to that hash. Then you have
$customer->[0]{_address}[0] $customer->[0]{_address}[1]
and looping becomes much easier:
my $arrayref = $customer->[0]{_address}; for my $address (@$arrayref) { # do whatever with $address ... }
But if you really have those column names (_address1,_addresss2,...,_adressn) in your tables, then the database design is flawed. You might want to normalize the addresses out to a another table.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re: Hash name variable substitution
by shmem
in thread Hash name variable substitution
by peterb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |