I want to call a subroutine by passing around 4 arrays to it and then get the first value of each array and then create a new array(array of first elements of arrays that are passed) in the subroutine and then return back that array. Here is the code I tried with
my @a = (97,34,6,7);
my @b = ("A", "B", "F", "D");
my @c = (5..15);
my @d = (1..10);
my @tailings = popmany ( \@a, \@b, \@c, \@d );
print @tailings;
sub popmany {
my @retlist = ();
for my $aref (@_) { #1
my $arrele = @$aref; #2
push @retlist , $arrele #3
}
return @retlist;
}
Here in #1 I use a loop and get the first array , then in line 2 I assign the whole array to a variable, thinking that by default the perl will only store the first variable of array into @arrele. the I push the $arrele to a new array @retlist , Sorry I dint refer any notes, so my procedure might be wrong. But this is throwing me a output like 441110
which has no sense.
Please explain me the code how can I do that.
popmanyas a name is doubly misleading.popremoves the last element of an array and returns it. This returns the first value without altering the arrays.