Created
December 6, 2021 11:05
-
-
Save rozer007/097a90f37bce688778eebddcfe445cfe to your computer and use it in GitHub Desktop.
Hashes in Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1. What symbol is use to represent the hashes in perl? | |
ans: The % symbol is use to represent hashes in perl. | |
Q2.How can we convert a hashes to an array? | |
ans: We can convert a hashes to an array using this syntax: my @var = %hashes. | |
Q3.How can we access item from a hash in perl? | |
ans: We will use sigil $ while accessing the item in hash. syntax: hash | |
Q4.What function is use to check if a key in present in a hash? | |
ans We use exists operator to check whether a key is present or not. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1.What will be the output of this statement: | |
my %hash=("a"=>96, | |
"b"=>98, | |
"c"=>99); | |
print $hash{"c"}++; | |
a) 99 | |
b) 100 | |
c) error | |
d) c=>99 | |
ans: a) | |
Q2.What will be the output: | |
my %hash=("a"=>96,"b"=>98,"c"=>99); | |
my @var=%hash; | |
print @var[2]; | |
a) b | |
b) a | |
c) error | |
d) not able to defined. | |
ans: b) | |
Q3.What will this statement give: | |
my %hash=("a"=>96,"b"=>98,"c"=>99); | |
my $k=keys %hash; | |
print $k; | |
a) all the keys | |
b) The fisrt key in the hash | |
c) the length of the hash | |
d) the number of keys in hash | |
ans: d) | |
Q4)What will be the output of the statement: | |
my %hash=("a"=>96,"b"=>98,"c"=>99); | |
while(my($k,$v)=each(%hash)) | |
{ | |
$hash{$k}++; | |
}; | |
my @arr=@hash{'a','b','c'}; | |
print @arr; | |
a) 96,97,98,99 | |
b) 969899 | |
c) 97,99,100 | |
d) 9799100 | |
ans: d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment