in reply to Re^2: Error when running on larger files
in thread Error when running on larger files
I just generated a 5 million line file that approximates your format:
#! perl -slw use strict; for( 1 .. 5e6 ) { my $n1 = int( rand 100 ); my $n2 = int( rand 1e6 ); printf "w\t%d\t%d\t75\t75M\t0\n", $n1, $n2; printf "c\t%d\t%d\t75\t75M\t0\n", $n1, $n2 - int( rand 1000 ) + 50 +0; } __END__ C:\test>head 1166792.dat w 70 437286 75 75M 0 c 70 437579 75 75M 0 w 50 852386 75 75M 0 c 50 852473 75 75M 0 w 45 45196 75 75M 0 c 45 45695 75 75M 0 w 83 1739 75 75M 0 c 83 1590 75 75M 0 w 31 838500 75 75M 0 c 31 838902 75 75M 0
And wrapped your posted snippet up to allow it to run:
#! perl -slw use strict; open my $IN2, '<', '1166792.dat' or die $!; my( %store, %Tally ); while (<$IN2>) { chomp $_; next if eof; my @F2 = split( "\t", $_ ); #Split each tab-delimite +d field my $partner = <$IN2>; my @F3 = split( "\t", $partner ); #Split each tab-delimite +d field $store{ ( abs( $F2[2] - $F3[2] ) + 1 ) }++; ( $F2[2], $F3[2] ) = ( $F3[2], $F2[2] ) if $F2[2] > $F3[2]; $Tally{ $F2[1] }{ $F2[2] }{ $F3[2] }++; } foreach my $key ( sort { $a <=> $b } keys %store ) { print "$key\t$store{$key}\n"; } foreach my $chr ( sort { $a <=> $b } keys %Tally ) { foreach my $value1 ( sort { $a <=> $b } keys %{ $Tally{$chr} } ) { foreach my $value2 ( sort { $a <=> $b } keys %{ $Tally{$chr}{$ +value1} } ) { print "$chr\t$value1\t$value2\t$Tally{$chr}{$value1}{$valu +e2}\n"; } } }
And it runs to completion under 5.22 using just under 1.2GB.
Unless you're on a very memory constrained system, memory isn't the problem. Do you have somewhere you can post your failing datafile (zipped.)?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Error when running on larger files
by K_Edw (Beadle) on Jun 28, 2016 at 09:40 UTC | |
by BrowserUk (Patriarch) on Jun 28, 2016 at 09:58 UTC | |
by martell (Hermit) on Jun 28, 2016 at 10:25 UTC | |
by K_Edw (Beadle) on Jun 28, 2016 at 10:14 UTC | |
by BrowserUk (Patriarch) on Jun 28, 2016 at 10:30 UTC | |
by K_Edw (Beadle) on Jun 28, 2016 at 10:41 UTC | |
|