in reply to Re: Re:{2} Getting impossible things right (behaviour of keys)
in thread Getting impossible things right (behaviour of keys)
If this is going to be at all robust (umm and work as desired, sorry Blakem) I would change the sort to the following:
Oh also for the curious this is more modern form of the Schwartizian Transform which is a very cool trick. Unfortunately I cant remember the name of this version, nor the link to the excellent document I read about it. Hopefully someone that does will post a reply.
Your code doesnt actually sort the words by length. (Yes I _am_ deliberately storing the length before I quotemeta it.)my $regex=join '|', map {substr $_,2} sort {$a cmp $b} map {pack "SA*",length($_),quotemeta($_)} keys %su +fdata;
:-)
Update
Thanks to Amoe I reexamined this and realized I missed an opportunity for lazyness that geeky virtue:
Although IIRC perl will optimize the first into the second anyway, it does save about 10 chars or so..my $regex=join '|', map {substr $_,2} sort map {pack "SA*",length($_),quotemeta($_)} keys %su +fdata;
Oh also for the curious this is more modern form of the Schwartizian Transform which is a very cool trick. Unfortunately I cant remember the name of this version, nor the link to the excellent document I read about it. Hopefully someone that does will post a reply.
Update2
Tilly kindly supplied the link (see replies to this post). However the name I had in mind is the GRT or Guttman Rosler Transform.
DeMerphq / Yves
--
Have you registered your Name Space?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re (tilly) 6: Getting impossible things right (behaviour of keys)
by tilly (Archbishop) on Oct 24, 2001 at 15:34 UTC | |
Re: Re: Re: Re:{2} Getting impossible things right (behaviour of keys)
by blakem (Monsignor) on Oct 24, 2001 at 21:35 UTC | |
by demerphq (Chancellor) on Oct 25, 2001 at 00:11 UTC | |
by blakem (Monsignor) on Oct 25, 2001 at 01:49 UTC |
In Section
Seekers of Perl Wisdom