in reply to Self-Looping over hash - how to remove duplicate

If you accept that you get always same order (eg, not 3-1, instead 1-3) then you can print smaller as first index and larger as second.
if ($si == $sn) { $prod = $hash2{$si}; } else { $prod = $hash2{$si}*$hash2{$sn}; } my $tmp = $si; $si = $si <= $sn ? $si : $sn; $sn = $si == $sn ? $tmp : $sn; $spair{"$si-$sn"} = $prod;

Replies are listed 'Best First'.
Re^2: Self-Looping over hash - how to remove duplicate
by Jasper (Chaplain) on Oct 05, 2004 at 09:20 UTC
    Easier way to swap two values:
    ($a,$b)=($b,$a);
    So we get:
    ($si,$sn) = sort {$a<=>$b} $si, $sn
    I believe this is straight out of 'Learning Perl'