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
What is the purpose of goto expr statement?
Hi, I am a accountant. I am preparing a balance sheet but because of staff shortage and time pressures I cant complete it on time. There is lot of common data with last years which I need not retype and I can manage by editing last year’s balance sheet ? Is their any software on net where I can do this easily??
Why to use perl scripting?
There is no strict data types in perl unlike in other high level languages like Java so wouldn't that be a problem if a code in perl is to be a written by a big team of 20+ members ?"
How do I do fill_in_the_blank for each file in a directory?
Show the use of sockets for the server and client side of a conversation?
How can I implement the function overloading in Perl ? I read about the operator overloading, I do not know how to implement the function overloading. Thanks in advance ?
Which has the highest precedence, List or Terms? Explain?
When does circular reference occur?
Differentiate between arrays and list in perl.
What $! In perl?
Explain the difference between declarations of 'my' and 'local' variable scope in perl?
What does 'do' statement do in perl?
How to read a single line from a file in perl?
You want to connect to sql server through perl. How would you do that?