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
What is lexical variable in perl?
How to prevent file truncation in perl?
What are the steps involved in configuring a server using cgi programming?
What happens to objects lost in "unreachable" memory, such as the object returned by Ob->new() in `{ my $ap; $ap = [ Ob->new(), $ap ]; }' ?
Explain goto label?
Explain goto label, goto name, and goto expr?
What does undef function in perl?
Demonstrate subroutines in perl with a simple example.
what is the difference between java and cgi?
What is use of ‘->’ symbol?
Does Perl have reference type?
What is perl pop array function?
What is perl? What is the basic command to print a string in perl?
How many ways can we express string in Perl?
What does a die() function do in perl?