Hi there I have a text file that looks like this ..
-112.6 115.0 -120.8 153.7 -121.8 118.7 -118.5 142.8 -144.1 146.9 -119.7 124.5 -118.0 119.2
And I am writing a perl script to take each pair of values, place them in an array element according to whether they fit into a certain range ...for example, Phi (first value) between -180 and -175 and Psi (second value) between 60 and 70.
Thanks to all the help I have received from people on here recently, I now seem to have at least a semi working piece of code, as shown below:
#!/usr/bin/perl use warnings; # from command line. This file is a text file of phi psi angles as sel +ected # from ramachandran_3DplotA.pl script $input = $ARGV[0]; $output = $ARGV[1]; $n = 0; $o = 0; $v = 0; if(($ARGV[0] eq "-h") || ($ARGV[0] eq "")) { print "\n* Ramachandran_3D Plot* program\n"; print "-------------------------------------------\n"; print "Usage: perl ramachandran_3DplotB.pl <input file> <output fi +le>\n"; print "-------------------------------------------\n"; print "Prints out file for use in Graphis plotting program\n\n"; exit(1); } open(FILE, "$input") || die "ERROR: Unable to open $input FILE for rea +ding: $!\n"; open(OUT, ">>$output") || die "ERROR: Unable to open $output FILE for +writing: $!\n"; @file = <FILE>; for($i = -180; $i < 181; $i = $i+5) { $j = $i+5; $n++; $o = 0; for($k = -180; $k < 181; $k = $k+5) { $m = $k+5; $o++; @ranges = ([$i, $j, $k, $m]); @range_counts = (0) x @ranges; for $R (0..$#ranges) { for($f = 0; $f <@file; $f++) { $phi = substr($file[$f], 0, 6); $psi = substr($file[$f], 8, 6); print "$phi $psi\n"; if ($phi >=$ranges[$R][0] and $phi < $ranges[$R][1] and $psi >= $ranges[$R][2] and $psi < $ranges[$R][3]) { ++$range_counts[$R]; } } } for $R (0..$#ranges) { if($v < 73) { printf OUT "%d, ", $range_counts[$R]; $v++; } else { print OUT "\n"; $v = 0; } } } }
This script now works just fine for a reasonably small test file. But it doesnt fare so well on my actual file (which is about 22MB in size) .. in fact it just sits there and does nothing. I'm not sure quite why this is, would it be because the script as is is just terribly inefficient, or would it be that it simply cant handle large quantities of data, or what?
Any advice much appreciated

In reply to inefficient code? works on small files ok but not larger ones 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.