Sorry about that. Here is my code
my %fnameof; my %valueof; my @relation; my @second; my $mainfile; my $subfiles; { open ($testdataset, "datasetnew.txt") or die "Cannot open file"; @testdataset = <$testdataset>; close ($testdataset); open (STDOUT, ">>result.txt"); $fcount = 1; $secondcount = 0; @testdataset = grep { $_ ne '' } @testdataset; @testdataset = grep /\S/, @testdataset; foreach $dataline (@testdataset) { ($mainfile, $subfiles) = GetFileName($dataline); for ($mainfile) { $mainfile =~ s/^\s+//; $mainfile =~ s/\s+$//; } addtoHash($mainfile); @subfiles = @keywords = split(/;/, $subfiles); @subfiles = grep { $_ ne '' } @subfiles; @subfiles = grep /\S/, @subfiles; foreach $subfile (@subfiles) { $subfile =~ s/^\s+//; $subfile =~ s/\s+$//; addtoHash($subfile) unless ($_ ne ''); } #defining the relation of mainfile with subfiles. Each mainfil +e has relation weight = 1 with subfile. foreach $subfile (@subfiles) { $relation[$valueof{$mainfile}][$valueof{$subfile}] = 1 +; $second[$secondcount] = "$valueof{$mainfile};$valueof{ +$subfile}"; $secondcount++; } } #creating transitive relationship. ie: if A->B and B->C, then A->C foreach $seconditem (@second) { @test = split(/;/, $seconditem); $b = $test[0]; $c = $test[1]; for ($k = 1; $k<=$secondcount; $k++) { if ($relation[$c][$k] gt 0) { $relation[$b][$k] = $relation[$b][$k]+1; } } } PrintArray(); } #get mainfile and subfiles sub GetFileName{ my $item = $_[0]; @datasplit = split(/\t/, $item); $mainfile = @datasplit[0]; $subfiles = @datasplit[1]; return ($mainfile, $subfiles); } sub addtoHash{ my $file = $_[0]; $exist = 0; for ($i = 0; $i < $fcount; $i++) { if ($fnameof{$i} eq $file) { $exist = $i; } } if ($exist == 0) { $fnameof{$fcount}= $file; $valueof{$file} = $fcount; $fcount++; } } sub PrintArray(){ for($i=1;$i<$fcount; $i++) { for($j=1;$j<$fcount;$j++){ if (defined ($relation[$i][$j])) { print $fnameof{$i}."-".$relation[$i][$j]."->".$fnameof +{$j}."\n"; } } } print "\n"; }
And Here is sample dataset:
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;
But this dataset is actually huge. It's about 48MB. I have 1GB memory in my comp. I ran this program on Windows and Fedora core, but the resut is the same: blank --(with the 48MB dataset). PS: If there are any other points that can improve my code, please let me know.

In reply to Re^2: out of memory problem by perlbeginner10
in thread out of memory problem by perlbeginner10

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.