in reply to GOLF challenge: destroy dup array elements


The slickest way?

This one isn't mine (it came from Effective Perl Programming):

sub r{ keys%{{map{$_,1}@_}} }
HTH,
jynx

Replies are listed 'Best First'.
Re: Re: GOLF challenge: destroy dup array elements
by Sidhekin (Priest) on Sep 06, 2001 at 21:20 UTC

    Nope -- it stringifies everything, which I understand to be contrary to specifications. However, it is inspiring:

    sub r{ values%{{map{$_,$_}@_}} }

    This preserves references as references -- does that meet the specs?

    The Sidhekin

      But wouldn't two items collide in this hash if their stringified representations were the same? For instance, wouldn't an object that stringified to "abc" and the actual string "abc" refuse to coexist in that hash.

      I don't see how using values gets around the stringified nature of the keys.

      -Blake

        Most people are willing to forget about the existence of overloaded objects. The complaint is that keys returns everything in stringified form. So if elements of the hash included anonymous hashes (for instance), you would have a string indicating the hash, but you would no longer have a reference to the hash.

        Using values does not protect you from overload collisions, but it does protect you from returning stringified versions of everything.