K
Kirk Is
I've been using Perl for at least 10 years and I'm kind of surprised I
haven't run into this one before, so I want to see if I'm interpreting it
correctly...
If I have a trivial funtion returning a list
sub getarray{
return ("x","z","y");
}
then
@files = getarray();
@files = sort @files;
does 'what I expect' while trying to be "clever" and inline it
@files = sort getarray();
Doesn't...because when the first argument to sort is a subroutine,
it tries to use it as the comparison function.
On the other hand, experimentally,
@files = sort &getarray();
Works...hmm, I guess the upshot is I'm a little fast and loose
with whether I call functions with & or not and this is one of the
relatively few times it comes back to bite me...any suggestions
on the preferred method to avoid this kind of problem?
haven't run into this one before, so I want to see if I'm interpreting it
correctly...
If I have a trivial funtion returning a list
sub getarray{
return ("x","z","y");
}
then
@files = getarray();
@files = sort @files;
does 'what I expect' while trying to be "clever" and inline it
@files = sort getarray();
Doesn't...because when the first argument to sort is a subroutine,
it tries to use it as the comparison function.
On the other hand, experimentally,
@files = sort &getarray();
Works...hmm, I guess the upshot is I'm a little fast and loose
with whether I call functions with & or not and this is one of the
relatively few times it comes back to bite me...any suggestions
on the preferred method to avoid this kind of problem?