develooper Front page | perl.beginners | Postings from March 2002

RE: Newbie Help please.

Thread Previous | Thread Next
Timothy Johnson
March 31, 2002 20:33
RE: Newbie Help please.
Message ID:
     As for the second question, the answer is yes and no.  As far as the
programmer is concerned for the most part the basic difference between
arrays and hashes is that hashes have named keys, but you will normally use
them in different situations.  They are also stored differently, but I
admittedly don't know the details there.

     Arrays, for example, are often more suited for situations in which you
need to store a list of things that have something in common.  Perhaps they
are all lines of a file, or perhaps they are usernames, or words in a
string.  I've always thought that in a sense an array is like a hash with
one key and multiple values.  (If that confuses you just forget it, because
the way I see things is not always the most intuitive way for everyone

     A hash is a good way to keep a list of items in which each key is
associated with its value in the same way.  In your example, you can use the
hash to call up an object by referring to its color.  For this reason, you
will sometimes hear them referred to as "Associative Arrays".

-----Original Message-----
From: Ahmed Moustafa
To:; Sa
Sent: 3/31/02 5:04 AM
Subject: Re: Newbie Help please.

Sa wrote:
> #!/usr/bin/perl -w
> $map{"red"} = "apple";
> $map{"green"} = "grass";
> $map{"blue"} = "ocean";
> print "A string please: "; chomp ($some_string = <STDIN>);
> print "The value for $some_string is $map($some_string)\n";
> When I run it though I get the following complaint from perl:
> A string please: blue
> Use of uninitialized value in concatenation (.) at ./ line 6,
> line 1.
> The value for blue is (blue)

In line 6, it's $map{$some_string} not $map($some_string).

Ahmed Moustafa

To unsubscribe, e-mail:
For additional commands, e-mail:

This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About