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 Polymorphism in Perl?
what is Perl one liner?
What package you use to create a windows services?
List all the features of perl programming?
How to close a directory in perl?
Which guidelines by Perl modules must be followed?
What are the arguments and what do they mean in perl programming?
Define print() function in perl?
Explain the use of 'my' keyword in perl?
what are the steps involved in reading a cgi script on the server?
There are two types of eval statements i.e. Eval expr and eval block. Explain them.
How to read multi lines from a file in perl?
Enlist the advantages of using c over perl?
how to get back up from private character editor which is saved in the format of .udf
How will you access an element of a perl array?