CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Need to speed up Perl script: Edit Log



Gorgarian
New User

Dec 18, 2012, 1:23 PM


Views: 1561
Need to speed up Perl script

Hi guys,

I have written a few programs, not so much in perl. I have recently written a program to compare two hash tables (the files are huge), and could benefit from some advice on how to make my code more efficient. The script is taking days to run.

Data -- key value

TAAAACTGTATTAACCA 29
TAAGCGGTTGTGACAGA 63
AAGATTAGTATAGGACA 30
AATTAAATGCTCTCTCC 81
ATGTATCCAATCAGCTC 176
AGAACCCCTTCAAGGAA 34
AGCTGGCAGGCCCCCAC 32
CTCTGTGCAGCAATAAG 52
CTCCCCAAATGCCCTCC 34
AATTGCACAACCAGGGT 123

#!/usr/local/bin/perl

use strict;
use warnings;

open (F, 'F.dump');
print "File F.dump opened \n";

Step through the input file, taking $blocksize chunks.

# Read in a block of records from the female dataset
# and append to the female hash table

foreach (1..$blocksize){
my $row = <F>;
chomp($row);
my @record=split(' ', $row);
push (@array, @record);
last if (eof(F));
}
%tmphash2=@array;
%fhash=(%fhash, %tmphash2);
$a=($#array+1)/2;
print "$a records from file F.dump read into linear array \n";
print " added to Female hash, now ".keys(%fhash)." records \n";
undef @array;

I think the most obvious problem is that I am reading the lines from a file into an array, creating a hash table from the array, then appending the resulting hash table to that created in the previous iteration.

There is probably a way to read the lines from the file directly into the hash table. I just do not seem to be able to get anything to work. Any suggestions?

Full script attached.

First post.

Smile


(This post was edited by Gorgarian on Dec 18, 2012, 1:26 PM)


Edit Log:
Post edited by Gorgarian (New User) on Dec 18, 2012, 1:26 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives