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 do you mean by context of a subroutine?
Differences between die and exit.
How will you create a file in perl?
How to access parameters passed to a subroutine in perl?
What is the use of –w?
Which guidelines by Perl modules must be followed?
What does cgi program store?
How to do comment in perl?
How to dereference a reference?
how to connect cisco switch uisng perl script
Does Perl have objects? If yes, then does it force you to use objects? If no, then why?
How to read a file into a hash array?
Which functions in perl allows you to include a module file.
What is hash?
How can you define “my” variables scope in Perl and how it is different from “local” variable scope?