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 difference between exec and system?
What is confess function in perl?
How do I debug a perl program?
How to print escaping characters inside a string in perl?
How to open and read data files with Perl
Explain perl one-liner?
Why do we use "use strict" in perl?
Show the use of sockets for the server and client side of a conversation?
Difference between the variables in which chomp function work ?
If EXPR is an arbitrary expression, what is the difference between $Foo::{EXPR} and *{"Foo::".EXPR}?
How to access parameters passed to a subroutine in perl?
Explain join function in perl?
In Perl, there are some arguments that are used frequently. What are that arguments and what do they mean?
How to change a directory in perl?
How to know whether a key exists or not in perl?