Re: Need Hash Help
- From: Joe Smith <joe@xxxxxxxxx>
- Date: Tue, 17 Jul 2007 02:32:55 -0700
raymond@xxxxxxxxxxx wrote:
I'm trying to create a hash with name/answer pairs.
I retrieve a person's userid ($name) and their response ($answer) to a
multiple choice question in a poll.
I'm trying to store these into a simple hash:
$responses{ $name } = $answer;
If you have the name already and are looking to store or retrieve their
one-and-only-answer, that is the way to do it. If you are having problems,
it is somewhere else in your program not in that statement.
Once I complete getting all the different people's names and answers in one
question, I sort them by answer
perldoc -q 'by value'
then print out a single answer with all the names who chose that answer.
You say "single answer" which implies a hash keyed by answer, not by name.
You say "all the names" which implies the hash value will be an array of names.
So, by your own words, you are looking for a hash of arrays where the hash
is indexed by $answer and the value is is an anonymous array containing
multiple $name entries.
Any further questions should be accompanied by a short but functional program
showing what you've got so far, and should be posted to the comp.lang.perl.misc
newsgroup (not comp.lang.perl since this newsgroup is defunct).
-Joe
.
- Follow-Ups:
- Re: Need Hash Help
- From: raymond
- Re: Need Hash Help
- References:
- Need Hash Help
- From: raymond
- Need Hash Help
- Prev by Date: Re: How to use the Perl script to substitute the string ?
- Next by Date: Re: Need Hash Help
- Previous by thread: Re: Need Hash Help
- Next by thread: Re: Need Hash Help
- Index(es):
Relevant Pages
|
|