Schwartzian transform

Dermot paikkos at gmail.com
Wed Aug 13 11:33:08 BST 2014


Olé

Thank you Adrian. Your golf is good.

my $count = 1;
my @sorted =
    map { $ref->{ $_->[0] }->{position} = $count++; $ref->{ $_->[0] } }
    sort { $a->[1] <=> $b->[1] }
    map [ $_, $ref->{$_}->{position} ],
    keys %{ $ref };


I sometimes question the legibility of such code but as an exercise, it's
good to know.

That last expression is interesting, Let's see if I'm getting it. Modify
the value of {position} in that hashref then return the hashref. The ';'
allowing you to perform more than one operation in the map expression...I
feel a penny dropping.

Thanks,
Dermot.









On 13 August 2014 11:11, Adrian Lai <perl at loathe.me.uk> wrote:

> On 13 August 2014 10:33, Dermot <paikkos at gmail.com> wrote:
>
> > #    map { $ref->{ $_->[0] }->{position} => $count++ }
>
> You probably want = $count++, rather than =>.
>
> You possibly want:
>
> map { $ref->{ $_->[0] }->{position} => $count++; $ref->{$_->[0]} }
>
> Adrian.
>


More information about the london.pm mailing list