Consider the following example
#! /bin/perl
use strict;
sub sample
{
my @arr=(1,2,3,4);
return @arr;
}
my ($a,$b,$c,$d) = &sample;
print "$a\n$b\n$c\n$d\n";
In the above code, How can I get the $c without using the
arguments such as $a,$b.
I don't want to use any array to get the return values.
Answer Posted / guest
Try with the following program.
[code]
sub sample
{
my @arr=(1,2,3,4);
return @arr;
}
my $c=(&sample)[2];
print $c;
Variable 'c' will contain the value '3'.
Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
Write a program that shows the distinction between child and parent process?
What is the use of -n and -p options?
How to get help for perl?
How will you get the count of parameters passed to a perl subroutine?
Can you add two arrays together?
Comment on the scope of variables in perl.
There are some duplicate entries in an array and you want to remove them. How would you do that?
Write a program to concatenate the $firststring and $secondstring and result of these strings should be separated by a single space.
How do I read command-line arguments with Perl?
Which guidelines by Perl modules must be followed?
Define print() function in perl?
What is the use of -t?
How to deleting an existing file in perl programming?
What is it meants by '$_'?
How to read file into hash array ?