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

# 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       View All Answers


Please Help Members By Posting Answers For Below Questions

When do you use perl programming?

730


What is the purpose of goto expr statement?

641


Explain subroutine?

678


Define say() function in perl?

702


what is Perl one liner?

696


What is it meants by '$_'?

692


What does perl do in linux?

700


What is a chop() function in perl?

766


Give an example of using the -n and -p option.

753


How do you give functions private variables that retain their values between calls?

724


What is eval function in perl?

721


Explain string comparison operators in perl.

764


How to check the status of airplane mode (enable/disable) in perl for Android mobile?

2834


When does circular reference occur?

693


what is Chop & Chomp function does?

763