Re: use hash in a list
- From: Jim Gibson <jgibson@xxxxxxxxxxxxxxxxx>
- Date: Thu, 08 Sep 2005 07:13:02 -0700
In article <lQSTe.145443$Hk.7356@pd7tw1no>, <a@xxxxxxxx> wrote:
> my(%hashA,%hashB)
> how to populate %hashA and %hashB that are inside a list?
> Thanx
What does "hash inside a list" mean? I can guess that you are referring
to this construct for one hash:
my %hash = ( 'a' => 1, 'b' => 2 );
extended to two hashes:
my(%hash1,%hash2) = ('a'=>1, 'b'=>2), ('c'=>3, 'd'=>4);
except that doesn't work ("Useless use of a constant in void context").
This compiles:
my(%hash1,%hash2) = (('a'=>1, 'b'=>2), ('c'=>3, 'd'=>4));
except that all of the elements get assigned to %hash1. This is typical
for Perl, in that an array involved in an assignment will tend to
gobble up all remaining lvalues.
The short answer to your question is then: "You don't".
Is it so hard to write two lines?
my %hash1 = ('a'=>1, 'b'=>2);
my %hash2 = ('c'=>3, 'd'=>4);
If this is not what you want, then please be more explicit. It always
helps to include a short, complete program that demonstrates the
problem you are having and explain why the program is not doing what
you want.
FYI: this newsgroup is defunct. Please use comp.lang.perl.misc in the
future.
.
- Follow-Ups:
- Re: use hash in a list
- From: a
- Re: use hash in a list
- References:
- use hash in a list
- From: a
- use hash in a list
- Prev by Date: use hash in a list
- Next by Date: Re: use hash in a list
- Previous by thread: use hash in a list
- Next by thread: Re: use hash in a list
- Index(es):
Relevant Pages
|
|