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
Demonstrate subroutines in perl with a simple example.
What is the difference between exec and system?
What is the function of cgiwrap in cgi programming?
How to access parameters passed to a subroutine in perl?
What does `new $cur->{LINK}' do? (Assume the current package has no new() function of its own.)
“The methods defined in the parent class will always override the methods defined in the base class”. What does this statement means?
Explain what is the scalar data and scalar variables in Perl?
You want to empty an array. How would you do that?
What are the features of perl language?
Explain perl. When do you use perl for programming? What are the advantages of programming in perl?
what is Polymorphism in Perl?
Explain the arguments for perl interpreter.
what are the steps involved in reading a cgi script on the server?
What is the use of -t?
What are the benefits of perl in using it as a web-based application?