Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thanks!#!/usr/bin/perl use warnings; use strict; chomp (my @array = <DATA>); my @map = @array; my %hash = (); my %hash2 = (); foreach my $parent (@array) { foreach my $child (@map) { if ($child =~ /$parent/) { push @{$hash{$parent}}, $child unless ($child eq $parent); } } } my @children; my @parent; my %family = (); my %seen = (); foreach my $key (keys %hash) { push @parent, $key; push @children, @{$hash{$key}}; } foreach my $parent (@parent){ foreach my $child (@children) { if ($child eq $parent) { $seen{$parent}++ } } } foreach my $parent (@parent) { if (!$seen{$parent}++ ){ print "Parent: ", $parent, "\n"; foreach (@{$hash{$parent}}) { print " child: $_ \n"; } } } __DATA__ Test_100.26.35.6_1 Test_100.26.35.6_13 Test2_9.25.6.27_2 Test2_9.25.6.27 Test_100.26.35.6 Test_100.26.35.6_10 Test3_28.20.116.210_ide Test3_28.20.116.210 Test4_28.25.6.21_45 Test4_28.25.6.21_45_25
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Algorithm performance enhancement needed
by dragonchild (Archbishop) on Apr 14, 2004 at 15:38 UTC | |
by Anonymous Monk on Apr 14, 2004 at 17:04 UTC | |
by dragonchild (Archbishop) on Apr 14, 2004 at 17:08 UTC | |
by Anonymous Monk on Apr 14, 2004 at 17:25 UTC | |
|
Re: Algorithm performance enhancement needed
by EdwardG (Vicar) on Apr 14, 2004 at 15:59 UTC | |
|
Re: Algorithm performance enhancement needed
by Roy Johnson (Monsignor) on Apr 14, 2004 at 18:01 UTC |