Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

If you want to empty an array then how would you do that?

0 Answers  


Can we load binary extension dynamically?

0 Answers  


Where the command line arguments are stored and if you want to read command-line arguments with Perl, how would you do that?

0 Answers  


What is the closure in PERL?

0 Answers  


How will you access an element of a perl array?

0 Answers  


How do I pass a command line argument in perl?

0 Answers  


write a perl script to find whether a given line of text is starting and ending with same word or not ???

2 Answers   CSS,


Which functions in perl allows you to include a module file. State their differences.

0 Answers  


Explain the functioning of conditional structures in perl.

0 Answers  


Why we use "use lib $path"?

1 Answers  


What is the difference between die and exit in perl?

0 Answers   HCL,


What rules must be followed by modules in perl.

0 Answers  


Categories