in reply to Until loop / unique
#! /usr/bin/perl -l my $zoo = { Mountain => { Dragon => 'Deadly', Troll => 'Deadly', Nymph => 'Oread +', Snake => 'Deadly' }, Cave => { Dragon => 'Deadly', Spider => 'Poisonous', Troll => 'Deadl +y', Ogre => 'Deadly' }, Forest => { Elf => 'Dark', Troll => 'Deadly', Nymph => 'Alseid', Spi +der => 'Hairy' }, Lake => { Nymph => 'Naiad', Snake => 'Poisonous', Serpent => 'Deadly +' }, Sea => { Kraken => 'Monstrous', Serpent => 'Monstrous' } }; sub each_uniq { my @refs = @_; my %seen = (); sub { while (@refs) { my @pair = each %{$refs[0]} or shift @refs and next; return @pair unless $seen{$pair[0]}++; } return; } } my $iter = each_uniq(values %$zoo); print join(", ", $iter->()) for 1..5;
Update. I read the previous questions monkini has asked, and it would appear the problem is largely unrelated to questions asked. From what I gather, he has a number of clusters each with a number of (labelled) points, and distances between points given. The problem apparently is to list the pairs of points in a cluster sorted by their distance, for each cluster separately. If so, the solution is to map clusters to points (HoA), iterate, slice map slice sort the HoH, print.
|
|---|