473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 4046
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian Genisio | last post by:
Hello all, I need to use a hash table for quick lookup... What is the best way to do it? My current solution uses stl::map, where I essentially do the following (not compilable code): ...
6
by: Joseph Lee | last post by:
Dear All, Is there a function in C# that will hash code a large byte array into an int value? I am searching for a hash function that will convert any size data(as for me the input is a byte...
8
by: mortb | last post by:
Hi, How do I write a GenerateHashcode function that will generate guaranteed unique hashcodes for my classes? cheers, mortb
7
by: Diane | last post by:
Hi everybody. Does anyone have any sample hash table implementation for separate chaining? I'm trying to implement it myself, but I'm stuck. Thanks!
24
by: kdotsky | last post by:
Hello, I am using some very large dictionaries with keys that are long strings (urls). For a large dictionary these keys start to take up a significant amount of memory. I do not need access to...
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
11
by: Douglas Dude | last post by:
how much time does it take to lok for a value - key in a hash_map ? Thanks
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
23
by: raylopez99 | last post by:
A quick sanity check, and I think I am correct, but just to make sure: if you have a bunch of objects that are very much like one another you can uniquely track them simply by using an ArrayList...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.