rockers has asked for the wisdom of the Perl Monks concerning the following question:
However, what I want is a bit more intelligence put to this function. For eg, if the user wants to put 2 elements into the same key, then the 2nd element must be 'push'ed to the already existing hash element, instead, this function, naively replaces the first element with the second, in case of such repetition. Can somebody help me in this regard? Thanks in advance.use strict; use warnings; sub getHash { my %hash; for(my $i=0;$i<4;$i++) { my $key = <STDIN>; chomp($key); my $val = <STDIN>; chomp($val); $hash{$key} = $val; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Converting a hash element into an array
by almut (Canon) on Jan 19, 2009 at 11:23 UTC | |
|
Re: Converting a hash element into an array
by holli (Abbot) on Jan 19, 2009 at 11:31 UTC | |
by rockers (Initiate) on Jan 19, 2009 at 11:39 UTC | |
by holli (Abbot) on Jan 19, 2009 at 11:42 UTC | |
|
Re: Converting a hash element into an array
by luckypower (Beadle) on Jan 19, 2009 at 11:41 UTC | |
by rockers (Initiate) on Jan 19, 2009 at 12:11 UTC | |
|
Re: Converting a hash element into an array
by hbm (Hermit) on Jan 19, 2009 at 13:35 UTC | |
|
Re: Converting a hash element into an array
by jethro (Monsignor) on Jan 19, 2009 at 18:26 UTC | |
|
Re: Converting a hash element into an array
by dorward (Curate) on Jan 19, 2009 at 11:19 UTC |