What could
$domchain =~/\S/g; $pdbchain =~/\S/g; chomp($domchain); chomp($pdbchain);
possibly accomplish?

I tried to fix some things in the code below, but, naturally, I could't try to run it (as I don't have the files).

use strict; use warnings FATAL => 'all'; use autodie; my $dir = "<my directory>"; my ( $dom_file_name, $csa_file_name ) = @ARGV; my %csa_hash; my %dom_hash; open my $csa_file, '<', $csa_file_name; while ( my $csa = <$csa_file> ) { my @csa_data = split( /\,/, $csa ); $csa_hash{ $csa_data[0] . $csa_data[3] } = $csa_data[4]; } close($csa_file); open my $dom_file, '<', $dom_file_name; while ( my $dom = <$dom_file> ) { my @dom_data = split /\s+/, $dom; my $domain = $dom_data[0]; next if exists $dom_hash{$domain}; open my $ind_dom_file, '<', $dir . $domain; while ( my $line = <$ind_dom_file> ) { chomp $line; my @ff = split /\s+/, $line; my $number = $ff[5]; my $CA = $ff[2]; push @{ $dom_hash{$domain} }, $number if $CA eq 'CA'; } close $ind_dom_file; } close $dom_file; while ( my ( $protein_dom, $residues_ref ) = each %dom_hash ) { for my $residue ( @{$residues_ref} ) { my $dom_chain = substr( $protein_dom, 0, 5 ); if ( $residue eq $csa_hash{$dom_chain} ) { print "$dom_chain $residue\n"; } } }

The idea was that it does the same thing as your code, but faster.


In reply to Re: Why is my program so slow even though I've used hashes? by akho
in thread Why is my program so slow even though I've used hashes? by Angharad

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.