in reply to Re: extracting redundant and unique items
in thread extracting redundant and unique items

AssFace,
I have been told that if you are going to throw away the values it is better not to even bother assigning the hash keys:
$hash{$thing}++; versus $hash{$thing} = undef;
I am not one for cargo cult programming. I honestly want to know why something is a better idiom for something than just doing it. With this said, I haven't thoroughly investigated this. I did do some benchmarks and the undef came out faster. Additionally, it makes sense that it isn't allocating any memory or doing any computation of the value.

Cheers - L~R

Replies are listed 'Best First'.
Re: Re: Re: extracting redundant and unique items
by AssFace (Pilgrim) on May 14, 2003 at 19:53 UTC
    That does make sense - since it doesn't do anything in terms of allocating memory for it and the like.

    I was mainly thinking in case they later wanted to know that there were 15 instances of X, 12 instances of Y, and 2 instances of Z, then the code would have that...

    But since they didn't say anything about wanting that, I suppose it would make more sense to do the undef instead and then later easily add in addition functionality like counting.

    -------------------------------------------------------------------
    There are some odd things afoot now, in the Villa Straylight.