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

What is lexical variable in perl?

523


How to prevent file truncation in perl?

502


What are the steps involved in configuring a server using cgi programming?

481


What happens to objects lost in "unreachable" memory, such as the object returned by Ob->new() in `{ my $ap; $ap = [ Ob->new(), $ap ]; }' ?

549


Explain goto label?

517






Explain goto label, goto name, and goto expr?

556


What does undef function in perl?

525


Demonstrate subroutines in perl with a simple example.

470


what is the difference between java and cgi?

563


What is use of ‘->’ symbol?

539


Does Perl have reference type?

526


What is perl pop array function?

536


What is perl? What is the basic command to print a string in perl?

487


How many ways can we express string in Perl?

540


What does a die() function do in perl?

543