Help - Search - Member List - Calendar
Full Version: Hash example
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Juan Gomez
Hi

I been hearing about hash on perl
can someone tell me a little bit about that and if you could add a
example
it would be very nice from you thank you

Owen
On Mon, 11 Jul 2005 10:16:17 -0500
"Gomez, Juan" <[Email Removed]> wrote:


QUOTE
I been hearing about hash on perl
can someone tell me a little bit about that and if you could add a
example
it would be very nice from you thank you



A hash is a set of relationships, for example

Item Cost

Beans 300
Carrot 200
Apple 250


etc

To create this relationship in perl, use the hash notation

%vegetable_costs = (Beans => 300
Carrots => 200,
Apple => 250 );

To refer to the hash, you use $vegetable_costs{Beans} for the cost of beans etc

for eaxample, your program might have a print statement like

print "The cost of beans is $vegetable_costs{Beans}n";


If you understand that, try putting the words "perl hash" into Google.



Owen


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.