Re: Iterated Hash Names



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.
.



Relevant Pages

  • Re: Iterated Hash Names
    ... push @userData, hash ... you get a different address if you keep references to ...
    (perl.beginners)
  • Iterated Hash Names
    ... I'm trying to create an array of hashes with hash names that are simply "user1", ... push @userData, hash ...
    (perl.beginners)
  • set like table
    ... What I need to do is mix many phrases into one continuous stream of midi ... (defstruct short-midi ... What I do is use a hash table with each hash table key being the note ... because we use push to populate the value list in the hash table ...
    (comp.lang.lisp)
  • Re: Question on File::Find
    ... Paul Lalli wrote: ... You didn't include the wanted option in your %findoption hash. ... what you think your push statement is doing ... sorry for the mistake, I presume I modified during posting, my mistake, ...
    (comp.lang.perl.misc)
  • Re: Question on File::Find
    ... Paul Lalli wrote: ... You didn't include the wanted option in your %findoption hash. ... what you think your push statement is doing ... If this is your real code, ...
    (comp.lang.perl.misc)