Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Until loop / unique

by oiskuu (Hermit)
on Nov 12, 2013 at 00:42 UTC ( [id://1062089]=note: print w/replies, xml ) Need Help??


in reply to Until loop / unique

So it's a matter of merging hashes? You could use an iterator, perhaps something like the following:
#! /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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-18 12:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found