On 3/12/06, Elliot Holden <[EMAIL PROTECTED]> wrote:
> my %dept_and_names = ("Accounting", "John Montgomery",
> "Customer Service", "Carol Jefferson",
> "Customer Service", "Jill Paulo",
> "Research and Development", "Jeffrey Johnson",
> "Accounting", "Sam Rantini",
> "Payroll", "Susan Choi",
> "Research and Development", "LaChonda Washington",
> "Customer Service", "Nancy Smith");
It looks as if you have several duplicate keys in your data. Remember,
a hash holds only a single value under each unique key. In the same
way that a new value stored into an array element like $fred[3]
over-writes an earlier one, a new name stored into
$dept_and_names{"Customer Service"} will wipe out any earlier one.
You (almost certainly) want to organize your data differently. For
example, under the key of "Customer Service", you could have a string
value such as "Carol Jefferson\nJill Paulo\nNancy Smith\n". By putting
a newline character after each name, you can use split() to get the
names back later. And it's easy to add a new person, whether or not
the department already exists in the hash:
$dept_and_names{$dept} .= "$name\n"
The .= operator will append a string to a variable, creating the
variable if necessary. Cheers!
--Tom Phoenix
Stonehenge Perl Training
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>