Re: use hash in a list



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



Relevant Pages

  • Re: deleting from hash question
    ... I'm trying to solve (though I'm using rails, this is more a ruby ... and then I had an Assignment model with: ... which correlates with the keys in the TASKS hash. ...
    (comp.lang.ruby)
  • Re: patch - linux 2.2.19 icmp firewall logging
    ... patch - linux 2.2.19 icmp firewall logging ... Hash: SHA1 ... Yours is an assignment; ...
    (Focus-Linux)
  • deleting from hash question
    ... I'm a ruby newbie and have what is probably a relatively simple problem ... I'm trying to solve (though I'm using rails, ... and then I had an Assignment model with: ... which correlates with the keys in the TASKS hash. ...
    (comp.lang.ruby)
  • Re: LDAP Server not connected error
    ... had experience passing Net::LDAP.new a hash, ... It will definitely work with the hash assignment - I do it here with ... I think Varun is missing the port setting though. ... The port setting should default to 389 if you don't set it. ...
    (comp.lang.ruby)
  • Hash Help Needed !
    ... I am making the following assignment during a loop: ... response_values is a simple hash containing key,value pairs and $time and $ip_address are simple scalar vars. ... I have also tried assigning as a referance, but that does not seem to work either: ...
    (perl.beginners)