[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] File::Sort



>At 12.28 12/19/97, Brian L. Matthews wrote:
>>You can sort of already do that:
>>
>>sub subname { a$ cmp $b};
>>$r = 'subname';
>>sort $r @array;
>
>Not under use strict.  :)
>
>>$r = sub { $a cmp $b };
>>sort {&$r} @array;
>
>Yes, that is what I want.  Matthias pointed it out to me; I don't know why
>I hadn't tried that.  I figured &$r would work on its own, and gave up when
>it didn't.  :)
>
>Thanks,
>
>--
>Chris Nandor

I'm not sure how this original thread got started, but I've been doing
this to dynamically change the type of sorts I want to do.  (And it even
works with strict :)

# Make sortorder whatever code reference I want
# sortorder must be a global or a local (dynamically scoped), not a
# my (lexically scoped) variable.
*sortorder = \&reversesort;

# You can define the codes before or after the assignment
sub reversesort { $b cmp $a };
sub forwardsort { $a cmp $b };

sort sortorder @array;

-- Gene



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch