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

# 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

Demonstrate subroutines in perl with a simple example.

916


What is the difference between exec and system?

1154


What is the function of cgiwrap in cgi programming?

974


How to access parameters passed to a subroutine in perl?

1008


What does `new $cur->{LINK}' do? (Assume the current package has no new() function of its own.)

984


“The methods defined in the parent class will always override the methods defined in the base class”. What does this statement means?

1063


Explain what is the scalar data and scalar variables in Perl?

984


You want to empty an array. How would you do that?

961


What are the features of perl language?

1144


Explain perl. When do you use perl for programming? What are the advantages of programming in perl?

925


what is Polymorphism in Perl?

1015


Explain the arguments for perl interpreter.

1336


what are the steps involved in reading a cgi script on the server?

986


What is the use of -t?

1022


What are the benefits of perl in using it as a web-based application?

955