Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: how can I group those links together?

by Athanasius (Archbishop)
on Dec 03, 2015 at 07:49 UTC ( [id://1149265]=note: print w/replies, xml ) Need Help??


in reply to how can I group those links together?

Hello plagent,

In the spirit of TMTOWTDI: You can also use one of the Set modules, such as Set::Tiny:

#! perl use strict; use warnings; use Set::Tiny qw( set ); my @groups; push @groups, set(split) while <DATA>; OUTER: while (1) { for my $i (0 .. $#groups - 1) { for my $j ($i + 1 .. $#groups) { unless ($groups[$i]->is_disjoint($groups[$j])) { $groups[$i] = $groups[$i]->union($groups[$j]); splice @groups, $j, 1; next OUTER; } } } last; } print $_->as_string, "\n" for @groups; __DATA__ A C C E D C L G J K O P I M L K

Output:

17:47 >perl 1468_SoPW.pl (A C D E) (G J K L) (O P) (I M) 17:47 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found