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


Please Help Members By Posting Answers For Below Questions

Difference between the variables in which chomp function work ?

625


Can inheritance be used in perl?

562


Explain the meaning of perl one-liner?

527


What is the purpose of redo statement?

536


What value is returned by a lone `return;’ statement?

574






When do you use perl programming?

596


Differentiate between c++ and perl.

610


You want to print the contents of an entire array. How would you do that?

535


What is it meants by '$_'?

545


What is confess function in perl?

551


What do you mean by context of a subroutine?

572


How interpreter is used in perl?

496


What does 'do' statement do in perl?

512


What are the advantages of perl programming?

546


Explain about the applications of perl?

550