in perl we want pass more than one array in function means,first we reference the array element into scalar variable.then we pass the variable through function parameter.
Inside function we must dereference the scalar variable into array
Example for Referencing and dereferencing the array
my(@id,@name,@age);
push(@id,101);
push(@name,'hari');
push(@age,23);
push(@id,102);
push(@name,20);
push(@id,103);
push(@name,24);
#referencing array
my $id=\@id;
my $name=\@name;
my $age=\@age;
#function calling
&detail($id,$name,$age);
sub detail
{
my $id=shift;
my $name=shift;
my $age=shift;
#dereferencing array
@ids=@$id;
@name=@$name;
@age=@$age;
foreach @ids(my $val)
{
print $id;
}
}
No comments:
Post a Comment