garymgordon
Programmer
I see the following but don't understand fully ... why and how the line that says FOREACH is actually being handled.
sub sort_by_number
{
return $a <=> $b;
}
@array = (1,2,4,8,144,72,288);
foreach (sort sort_by_number (@array))
{
print ("$_ "
;
}
Please help explain.
I understand that the sort function will sort the individual indexes from within the array and assign them individually to the variable of $_. But, how is the subroutine fitting in exactly how and where it is placed in the line that says:
foreach (sort sort_by_number (@array))
AND ...
I was under the impression that you were supposed to call a sub routine by adding a & in front of it. Is this not so? And, when would or would you not use the & in front of a sub routine to call it?
Thanks,
Gary
Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer
sub sort_by_number
{
return $a <=> $b;
}
@array = (1,2,4,8,144,72,288);
foreach (sort sort_by_number (@array))
{
print ("$_ "
}
Please help explain.
I understand that the sort function will sort the individual indexes from within the array and assign them individually to the variable of $_. But, how is the subroutine fitting in exactly how and where it is placed in the line that says:
foreach (sort sort_by_number (@array))
AND ...
I was under the impression that you were supposed to call a sub routine by adding a & in front of it. Is this not so? And, when would or would you not use the & in front of a sub routine to call it?
Thanks,
Gary
Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer