Welcome to Dream.In.Code
Become an Expert!

Join 149,529 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,506 people online right now. Registration is fast and FREE... Join Now!




hashes

 
Reply to this topicStart new topic

hashes, i want to know the meaning of this statement

hemarajun
17 Jun, 2007 - 10:23 PM
Post #1

New D.I.C Head
*

Joined: 13 Jun, 2007
Posts: 2


My Contributions
@hash{@array} = @array;

what is the meaning of this statement.

User is offlineProfile CardPM
+Quote Post

KevinADC
RE: Hashes
18 Jun, 2007 - 06:26 AM
Post #2

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 238



Thanked: 6 times
Dream Kudos: 50
My Contributions
it just makes a hash from whatever data is in the @array array. The keys and values will be the same.

CODE
@array = qw(foo bar bash 1 2 3);
@hash{@array} = @array;
foreach $key (keys %hash) {
   print "key = $key, value = $hash{$key}\n";
}

output:

CODE
key = 1, value = 1
key = bar, value = bar
key = bash, value = bash
key = 3, value = 3
key = foo, value = foo
key = 2, value = 2

User is offlineProfile CardPM
+Quote Post

kuratkull
RE: Hashes
20 Jun, 2007 - 07:01 AM
Post #3

New D.I.C Head
Group Icon

Joined: 1 May, 2007
Posts: 6


Dream Kudos: 250
My Contributions
QUOTE(hemarajun @ 17 Jun, 2007 - 11:23 PM) *

@hash{@array} = @array;

what is the meaning of this statement.


I haven't used Perl for some time now, but you could print out @hash after using the snippet.
I tried this in python and it didn't work:
TypeError: dict objects are unhashable

Hope this helped a bit.
User is offlineProfile CardPM
+Quote Post

KevinADC
RE: Hashes
20 Jun, 2007 - 06:49 PM
Post #4

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 238



Thanked: 6 times
Dream Kudos: 50
My Contributions
kuratkull,

did you not see my reply? He can't print @hash anyway, as its a hash that is created, %hash, not an array.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:55PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month