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
How can you replace the characters from a string and save the number of replacements?
What are scalars in perl?
What are stdin, stdout and stderr?
How to deleting an existing file in perl programming?
There are two types of eval statements i.e. Eval expr and eval block. Explain them.
what is Perl one liner?
what is the function that is used to identify how many characters are there in a string?
Why aren't Perl's patterns regular expressions?
How the interpreter is used in Perl?
How to do comment in perl?
How to open and read data files with Perl
Explain perl one-liner?
Write a program to decode the data in the form using cgi programming
List the files in current directory sorted by size ?
What is the difference between single (') and double (") quote in a string in perl?