in reply to quandery about a grep statement

That seems an awful amount of work. I haven't analyzed the code yet, but from the little information you gave, this seems to work as well and be more understandable:
sub beautify { my %temp = map { $_ => 1 } @_; return sort { $a <=> $b } keys %temp; }

Of course, if you have a large array, this may not be efficient enough - you are making several copies of the array and on very large arrays that could hurt.

Your current code works ( I think ) because:

  1. If it is a new key $new{$_} and $old{$_} will both be 1 and grep will include that key in the returned array
  2. If it isn't an new key,
    1. $new{$_} will be incremented and $old{$_} will not. Thus, for example, $new{$_} == 2 and $old{$_} == 1.
    2. Your secondary test is $new{$_}+1 == $old{$_}. Since we have just established $new{$_} > $old{$_}, it is obviously true that $new{$_} + 1 > $old{$_} and the second tertiary test will return 0.
You are working way too hard at this. Let the hash worry about enforcing unique keys.

UPDATE: I just read this again and realized the tone is very wrong. I am not trying to be rude, but I suddenly slipped into writing a math proof. mikfire

Replies are listed 'Best First'.
Re (tilly)2: quandery about a grep statement
by tilly (Archbishop) on Mar 29, 2001 at 23:44 UTC
    That map of yours is a lot more work than you may realize! (Or will be until Perl 5.6.1.)