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

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

684


What is the use of -n and -p options?

779


How to get help for perl?

751


How will you get the count of parameters passed to a perl subroutine?

705


Can you add two arrays together?

691


Comment on the scope of variables in perl.

704


There are some duplicate entries in an array and you want to remove them. How would you do that?

688


Write a program to concatenate the $firststring and $secondstring and result of these strings should be separated by a single space.

827


How do I read command-line arguments with Perl?

783


Which guidelines by Perl modules must be followed?

770


Define print() function in perl?

716


What is the use of -t?

729


How to deleting an existing file in perl programming?

672


What is it meants by '$_'?

692


How to read file into hash array ?

778