HI Monks, I would like to check whether the keys of two hashes are same and work on them. The hashes should be in the same order as the input file. Since, we cant compare the hashes directly and have to loop over the key and value pair the larger files are taking very long to be finished.
I have attached my piece of code Could you please give suggestions to imporve it please
Thanks
#!/usr/local/bin/perl -w use strict; use Getopt::Long; use Tie::IxHash; my ($bpfile , $intfile, $out); my $usage = " USAGE: perl beadpool_int.pl -bpfile <file with snp,chr, +beadpoolid> -int <intensities file from b2i>\n"; GetOptions("bp=s" =>\$bpfile, "int=s" =>\$intfile, "out=s" =>\$out) || warn "Error $!\n"; if(!$bpfile) {die "\n$usage\n"}; my %beads; tie my %ints,"Tie::IxHash"; open BP, "<$bpfile" or die $!; open INT, "<$intfile" or die $!; open OUT, ">$out"or die $!; while (my $line= <BP>) { chomp $line; my @bp = split(/,/,$line); $beads{$bp[0]} = $bp[2]; } close BP; #my ($snp, @array) my @intensities; while (my $line = <INT>){ chomp $line; my $LABELS_REGEX =qr(^SNP\s+Coor); if ($line !~ $LABELS_REGEX) { my ($snp, $coor, $allele,@array) = split(/\t/,$line); $ints{$snp} = \@array; @intensities = @array; } } close INT; foreach my $snp(keys %ints) { foreach my $snpbs(keys %beads){ if($snp eq $snpbs){ my @ints; for(my $i = 0;$i<scalar(@intensities);$i++) { push @ints, $ints{$snp}[$i] ; } print OUT "$beads{$snpbs}\t$snp\t", join("\t",@ints), "\n"; } #print OUT "\n"; } }

Thanks for your time and suggestions

In reply to To make the comparison work faster by Anonymous Monk

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.