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
# Here is another solution
use strict;
sub sample {
my @arr = (1,2,3,4);
return \@arr; # return the array reference
}
my $aref = &sample;
print $aref->[2];
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is the purpose of redo statement?
What does next statement do in perl?
What is the tk module?
What is the use of -w, -t and strict in Perl?
What are scalars in perl?
Explain chomp?
What is the use of -t?
Define say() function in perl?
How to read file into hash array ?
Explain 'grep' function.
How can I implement the function overloading in Perl ? I read about the operator overloading, I do not know how to implement the function overloading. Thanks in advance ?
Explain strftime() function in perl?
What is the use of 'ne' operator?
Does Perl have objects? If yes, then does it force you to use objects? If no, then why?
When do you use perl programming?