What is a hash?

Answer Posted / prabhath kota

As friends said above, its otherwise called as associative
array. It has lot of advantages over perl.

Here we can keep the values in a structured way, that
structured way comes from key-value pairs.

Eg: (The syntax given above are also correct, but the below
representation is much better in look and feel)

my %hash_example = ( a => 10,
b => 20,
c => 30 );
keys : a,b,c
values : 10,20,30

Features of Hash :
##################
1) Keys should always be unique where as values may not be
unique

(Right)
my %hash_example = ( a => 10,
b => 10,
c => 10 );

(wrong)
my %hash_example = ( a => 10,
a => 20,
a => 30 );

2) keys (%hash_example) will return an array containing only
keys

my @keys = keys(%hash);

3) similary for values
my @values = keys(%values);

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

List the prefix dereferencer in Perl.

572


What does a die() function do in perl?

543


Which of these is a difference between Perl and C++ ?

570


What is the use of -n and -p options?

604


Which functions in Perl allows you to include a module file or a module and what is the difference between them?

525






Is there any way to add two arrays together?

574


How to create a directory in perl?

530


Which statement has an initialization, condition check and increment expressions in its body? Write a syntax to use that statement.

547


What is the difference between perl list and perl array?

471


I have one question regarding to eval function. I know eval function is use for error checking but I am not able to understand below line. eval \'exec perl -S $0 ${1+\"$@\"}\' if 0; $0 for script name $@ set if error occur

1612


Can inheritance be used in perl?

553


What is the purpose of goto expr statement?

480


What are the different string manipulation operators in perl?

534


You want to download the contents of a url with perl. How would you do that?

505


Differentiate between use and require, my and local, for and foreach and exec and system

485