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
Try with the following program.
[code]
sub sample
{
my @arr=(1,2,3,4);
return @arr;
}
my $c=(&sample)[2];
print $c;
Variable 'c' will contain the value '3'.
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
Write the program to process a list of numbers.
How to turn on Perl warnings? Why is that important?
Show the use of sockets for the server and client side of a conversation?
What is the purpose of _package_ literal?
What is the function of virtual documents in cgi programs?
How to open and read data files with Perl
How will you declare a variable in perl?
Demonstrate subroutines in perl with a simple example.
What are the various perl data types based on the context?
How to print escaping characters inside a string in perl?
what is the difference between java and cgi?
How to find the length of an array in perl?
Does Perl have reference type?
How to get help for perl?
What does the qq{ } operator do?