Solution :
Both datatypes are used in PERL. Both of them are very useful in their respect.
Hash vs Array :-
(i) The basic differnce is the order maintain by both, array always keeps the order of elements inserted but hash will not do the same.
(ii) If data is at large level, than hash is best option as compare to array and at small level, traversing in array is much quicker than hash.
(iii) The symbol difference is there, array always nominated by @ whereas hash is denoting by % symbol.
(iv) The brackets differnce is there, array uses [] parenthesis whereas hash uses {} curly braces.
(v) The elements can be access from array by using index ($array[1]) whereas in hash use keys ($hash{'keys'}) for the same.
(vi) Declaration of both :
my @array = (1,2,3,4,5,6);
foreach my $i(@array){
print $array[$i];
}
my %hash = (1,2,3,4,5,6);
foreach my $keys(keys %hash){
print $keys." => ".$hash{$keys}."\n";
}
Both datatypes are used in PERL. Both of them are very useful in their respect.
Hash vs Array :-
(i) The basic differnce is the order maintain by both, array always keeps the order of elements inserted but hash will not do the same.
(ii) If data is at large level, than hash is best option as compare to array and at small level, traversing in array is much quicker than hash.
(iii) The symbol difference is there, array always nominated by @ whereas hash is denoting by % symbol.
(iv) The brackets differnce is there, array uses [] parenthesis whereas hash uses {} curly braces.
(v) The elements can be access from array by using index ($array[1]) whereas in hash use keys ($hash{'keys'}) for the same.
(vi) Declaration of both :
my @array = (1,2,3,4,5,6);
foreach my $i(@array){
print $array[$i];
}
my %hash = (1,2,3,4,5,6);
foreach my $keys(keys %hash){
print $keys." => ".$hash{$keys}."\n";
}