dunkirk_phil has asked for the wisdom of the Perl Monks concerning the following question:
and I want the links to be joined as a|b|c|d and j|k|l|m|n i.ie in my code below I want my %newTrailsToCombine hash to look likemy %T1 = ( 'a|b' => 'a|b', 'b|c' => 'b|c', 'c|d' => 'c|d', 'j|k' => 'j|k', 'k|l' => 'k|l', 'l|m' => 'l|m', 'm|n' => 'm|n' );
instead it looks likemy %newTrailsToCombine = ( 'a|b' => 'a|b|c|d', 'b|c' => 'a|b|c|d', 'c|d' => 'a|b|c|d', 'j|k' => 'j|k|l|m|n', 'k|l' => 'j|k|l|m|n', 'l|m' => 'j|k|l|m|n', 'm|n' => 'j|k|l|m|n' );
Below is my code , any help/ideas would be appreciated Thanks Phil%newTrailsToCombine$VAR1 = { 'm|n' => 'm|n|l|m', 'j|k' => 'j|k|k|l', 'k|l' => 'k|l|j|k|l|m', 'b|c' => 'b|c|a|b|c|d', 'a|b' => 'a|b|b|c', 'l|m' => 'l|m|k|l|m|n', 'c|d' => 'c|d|b|c'
#! /opt/perl/bin/perl -w use strict; use Data::Dumper; my %T1 = ( 'a|b' => 'a|b', 'b|c' => 'b|c', 'c|d' => 'c|d', 'j|k' => 'j|k', 'k|l' => 'k|l', 'l|m' => 'l|m', 'm|n' => 'm|n' ); my %trailsToCombine = %T1; my %newTrailsToCombine; my %clone_trailsToCombine; my $seenFirst; my %seen; %clone_trailsToCombine = %trailsToCombine; while (my($K, $V) = each (%trailsToCombine)) { my @Karr = split (/\|/,$V); my $tmp = $K; foreach my $i (@Karr) { while (my($SK, $SV) = each (%clone_trailsToCombine)) { if( $K eq $SK) { #ignore } elsif((my $count = grep /$i/,$SK) >= 1 ) { $tmp = $tmp."|$SK"; } else { #no match } } } if( ! exists $newTrailsToCombine{$K}) { $newTrailsToCombine{$K} = $tmp; } } #process_trailsToCombine(%trailsToCombine); print "\n Dumping \%newTrailsToCombine"; print Dumper(\%newTrailsToCombine);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Link Connectivity Algorithim
by liverpole (Monsignor) on Oct 30, 2006 at 14:17 UTC | |
by dunkirk_phil (Novice) on Oct 30, 2006 at 16:14 UTC | |
by liverpole (Monsignor) on Oct 30, 2006 at 16:34 UTC | |
|
Re: Link Connectivity Algorithim
by jbert (Priest) on Oct 30, 2006 at 17:19 UTC | |
|
Re: Link Connectivity Algorithim
by Anonymous Monk on Oct 30, 2006 at 11:22 UTC | |
by dunkirk_phil (Novice) on Oct 30, 2006 at 11:28 UTC | |
by Anonymous Monk on Oct 30, 2006 at 11:38 UTC | |
by dunkirk_phil (Novice) on Oct 30, 2006 at 13:55 UTC | |
by Anonymous Monk on Oct 30, 2006 at 15:02 UTC |