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

Explain USE and REQUIREMENT statements?

0 Answers  


What are the different ways to run cgi?

0 Answers  


write a script to display mirror image of a entered value and also check whether Palindrome

3 Answers   HCL, Persistent,


write a script to check whether user enter a value is a leap year or not?

3 Answers   Oracle, Persistent, ViPrak,


What is the purpose of goto expr statement?

0 Answers  


Differences between die and exit.

0 Answers  


Write a program that shows the distinction between child and parent process?

0 Answers  


Explain the internal working of cgi

0 Answers  


Explain string comparison operators in perl.

0 Answers  


What is epoch time in perl?

0 Answers  


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

0 Answers  


If EXPR is an arbitrary expression, what is the difference between $Foo::{EXPR} and *{"Foo::".EXPR}?

0 Answers  


Categories