Now that I understand what you are doing, here's code that generates the output you are looking for, albeit in a different order:
use strict; use warnings; my %mappings; while (<DATA>) { chomp; next if ! /\S/; s/^\s+//; s/\s+$//; my ($mainfile, $subfiles) = split /\s*,\s*/; my @subfiles = split /\s*;\s*/, $subfiles; @subfiles = grep /\S/, @subfiles; $mappings{$mainfile}{$_} = 1 for @subfiles; } # Generate transitive relationships. ie: if A->B and B->C, then A->C for my $A (keys %mappings) { for my $B (keys %{$mappings{$A}}) { ++$mappings{$A}{$_} for keys %{$mappings{$B}}; } } for my $key (keys %mappings) { print "$key - $mappings{$key}{$_} -> $_\n" for keys %{$mappings{$k +ey}}; } __DATA__ cancer,breast cancer; lung cancer; heart cancer; stomach cancer; breast cancer,foot cancer; foot cancer,some cancer; lung cancer,blood cancer; foot cancer; heart cancer,foot cancer; stomach cancer,foot cancer; blood cancer,some cancer;
Prints:
lung cancer - 2 -> some cancer lung cancer - 1 -> blood cancer lung cancer - 1 -> foot cancer cancer - 1 -> some cancer cancer - 1 -> lung cancer cancer - 1 -> blood cancer cancer - 1 -> breast cancer cancer - 4 -> foot cancer cancer - 1 -> heart cancer cancer - 1 -> stomach cancer blood cancer - 1 -> some cancer breast cancer - 1 -> some cancer breast cancer - 1 -> foot cancer heart cancer - 1 -> some cancer heart cancer - 1 -> foot cancer foot cancer - 1 -> some cancer stomach cancer - 1 -> some cancer stomach cancer - 1 -> foot cancer
In reply to Re^5: out of memory problem
by GrandFather
in thread out of memory problem
by perlbeginner10
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |