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.

Answers were Sorted based on User's Feedback



Consider the following example #! /bin/perl use strict; sub sample ..

Answer / 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

Consider the following example #! /bin/perl use strict; sub sample ..

Answer / guest

# Here is another solution

use strict;
sub sample {
my @arr = (1,2,3,4);
return \@arr; # return the array reference
}

my $aref = &sample;
print $aref->[2];

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More CGI Perl Interview Questions

Define say() function in perl?

0 Answers  


What is the difference between $array[1] and @array[1]?

1 Answers  


What does undef function in perl?

0 Answers  


Differentiate between arrays and list in perl.

0 Answers  


How to replace perl array elements?

0 Answers  






How can you call a subroutine and identify a subroutine?

0 Answers  


How do you find the length of an array?

0 Answers  


What does `new $cur->{LINK}' do? (Assume the current package has no new() function of its own.)

0 Answers  


What does delete function do in perl?

0 Answers  


What is the difference between use and require in perl programming?

0 Answers  


How to sort arrays in perl?

0 Answers  


In CPAN module, name an instance you use.

0 Answers  


Categories