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.

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

What do you mean by context of a subroutine?

978


Differences between die and exit.

995


How will you create a file in perl?

990


How to access parameters passed to a subroutine in perl?

954


What is the use of –w?

934


Which guidelines by Perl modules must be followed?

1016


What does cgi program store?

909


How to do comment in perl?

948


How to dereference a reference?

980


how to connect cisco switch uisng perl script

3847


Does Perl have objects? If yes, then does it force you to use objects? If no, then why?

953


How to read a file into a hash array?

1044


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

990


What is hash?

1064


How can you define “my” variables scope in Perl and how it is different from “local” variable scope?

1129