Skip to content

Instantly share code, notes, and snippets.

@rozer007
Last active December 6, 2021 09:34
Show Gist options
  • Save rozer007/8c7044138bdaf07e992a8b086aba213a to your computer and use it in GitHub Desktop.
Save rozer007/8c7044138bdaf07e992a8b086aba213a to your computer and use it in GitHub Desktop.
Arrays in Perl
Q1.How can we find the length of the string ?
ans: scalar @array_name will give the length of the array.
Q2. What is the use grep function?
ans: grep function is use to filter out the array according to condition or expression.
Q3.How can we remove a slice of array from an array?
ans: we can use splice function to remove a slice of elements from an array.
Q4. What is the function of unshift?
ans: The unshift function will add a element at the front of the array.
Q1.What will be the output of the statement:
my $arr="1,2,3,4,5";
print split/","/,$arr;
a) 12345
b) 1,2,3,4,5
c) "1,2,3,4,5"
d) None of the above
ans: b)
Q2 What will be the output of the code below:
my @arr=(1,2,3,4,5);
print pop @arr,5;
a) 5
b) 55
c) 1234
d) none of the above
ans: b)
Q3. What will be the output of this statement:
my @arr=(1,2,3,4,5);
for (@arr)
{
print $_+2;
}
a) 12345
b) 34567
c) 23456
d) none of the above
ans: b)
Q4.What will be the output of this statement:
my @arr=(1,2,3,4,5);
my($a,$b,$c)=@arr;
print $c;
a) 1
b) 3
c) 5
d) none of the above
ans: c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment