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
When do you use perl programming?
What is the purpose of goto expr statement?
Explain subroutine?
Define say() function in perl?
what is Perl one liner?
What is it meants by '$_'?
What does perl do in linux?
What is a chop() function in perl?
Give an example of using the -n and -p option.
How do you give functions private variables that retain their values between calls?
What is eval function in perl?
Explain string comparison operators in perl.
How to check the status of airplane mode (enable/disable) in perl for Android mobile?
When does circular reference occur?
what is Chop & Chomp function does?