469,284 Members | 2,488 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,284 developers. It's quick & easy.

use hash in a list

a
my(%hashA,%hashB)
how to populate %hashA and %hashB that are inside a list?
Thanx
Sep 8 '05 #1
3 3992
In article <lQSTe.145443$Hk.7356@pd7tw1no>, <a@mail.com> 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.
Sep 8 '05 #2
a
I am going to write a program that is able to generate a list for employee
information.
The information is stored in a text file. The format is as follows:
Peter NY English
Jane ON French
Charles NY English

So, the program will ask the user to input the name of language, and output
the list of the employee information.
e.g:
Input
Please input language: English
Output
Peter NY
Charles NY

What data structure should I use?
Thanx

"Jim Gibson" <jg*****@mail.arc.nasa.gov>
???????:080920050713025927%jg*****@mail.arc.nasa.g ov...
In article <lQSTe.145443$Hk.7356@pd7tw1no>, <a@mail.com> 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.


Sep 9 '05 #3
a wrote:
Peter NY English
Jane ON French
Charles NY English


my %employee_by_language;
while (<>) {
my($name_co,$lang) =~ /(.* \w\w) (.*)/;
push @{$employee_by_language{$lang}},$name_co;
}
Sep 9 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Brian Genisio | last post: by
6 posts views Thread by Joseph Lee | last post: by
8 posts views Thread by mortb | last post: by
7 posts views Thread by Diane | last post: by
24 posts views Thread by kdotsky | last post: by
21 posts views Thread by Johan Tibell | last post: by
11 posts views Thread by Douglas Dude | last post: by
139 posts views Thread by ravi | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.