Re: Iterated Hash Names
- From: rwwebs@xxxxxxxxx (Jeff Pang)
- Date: Sun, 30 Sep 2007 23:42:27 +0800
2007/9/30, Mathew Snyder <theillien@xxxxxxxxx>:
I'm trying to create an array of hashes with hash names that are simply "user1",
"user2", "user3", etc. How do I use this method when adding one of the hashes
to the array?
my $user = "user" . $i;
(build hash...)
push @userData, hash
Why not create the anonymous hashs?like,
for my $i (1 .. 3) {
push @userData {'user' .$i => 'value1', 'key2' => 'value2' ...};
}
or maybe a HoH is better,as,
my %HoH = ( 'user1' => { key1 => value1,key2 => value2...},
'user2' => { key1 => value1,key2 => value2...}
...
);
If you really want to use a variable as hash's names,you may need to
eval a string,which is not good so.
.
- Follow-Ups:
- Re: Iterated Hash Names
- From: Uri Guttman
- Re: Iterated Hash Names
- References:
- Iterated Hash Names
- From: Mathew Snyder
- Iterated Hash Names
- Prev by Date: Iterated Hash Names
- Next by Date: Re: Iterated Hash Names
- Previous by thread: Iterated Hash Names
- Next by thread: Re: Iterated Hash Names
- Index(es):
Relevant Pages
|