Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Perl Idioms Explained - keys %{{map{$_=>1}@list}}

by Aristotle (Chancellor)
on Aug 04, 2003 at 20:12 UTC ( [id://280778]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Idioms Explained - keys %{{map{$_=>1}@list}}
in thread Perl Idioms Explained - keys %{{map{$_=>1}@list}}

Note that this is slightly broken as is. To be entirely correct, you have to say
my (%seen, $seen_undef); my @uniq = grep defined() ? !$seen{$_}++ : !$seen_undef++, @list;
Of course, if you're fiddling with objects which cannot be compared for equity by stringification, it is still broken.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re3: Perl Idioms Explained - keys %{{map{$_=>1}@list}}
by dragonchild (Archbishop) on Aug 04, 2003 at 20:14 UTC
    Of course, if you're fiddling with objects which cannot be compared for equity by stringification, it is still broken.

    Well, so is every uniquification based on the keys of a hash! The point still stands that grep is faster than the original idiom presented, by orders of magnitude, if still as memory-hungry.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      I didn't dispute that. :) I just pointed out some of the more subtle points to keep in mind here.

      Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://280778]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found