I’m trying to do the following. I have a predefined list to be used as a “order by” on an given list.
my @orderby = ( 'car', 'boat', 'chicken', 'cat', 'dog', 'mouse');
or
my %orderby = ( 'car' => 0, 'boat' => 1, 'chicken' => 2, 'cat' => 3, 'dog' => 4, 'mouse' => 5);
my @list = ('boat', 'car', 'mouse', 'chicken');
I tried infinite ways to sort it and I didn’t get what I want. I have searched on google, and here, but I did not found the answer.
@list need to be sorted in that way:
sort @list using %orderby
The print that I want after the sort:
car, boat, chicken, mouse
BTW, @list can have duplicated entries:
my @list = ('boat', 'car', 'mouse', 'chicken', 'mouse', 'car');
In that case, the print need to be:
car, car, boat, chicken, mouse, mouse
Do you guys have a solution for that?
or maybe another approach.
Thanks!!
Or if you want to mess with people’s minds,