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 closure in PERL?
Which functions in perl allows you to include a module file. State their differences.
What is a perl references?
Define dynamic scoping.
What is automatic error handling in perl?
“Perl regular expressions match the longest string possible”. What is the name of this match?
What is the different between array and hash in perl programming?
How to prevent file truncation in perl?
How many types of operators are used in the Perl?
Differences between die and exit.
What does -> symbol indicates in Perl?
How do find the length of an array?
How to turn on Perl warnings? Why is that important?
What is perl? What is the basic command to print a string in perl?
What is the use of -n and -p options?