Your code (and substr) works fine. I just generated a 2.6 MB test file, put START and END at the appropriate places and the results are exactly what you want.

That leaves a couple fo possibilities.

  1. Either your method of checking is wrong.
  2. The large file is not quite in the format your expecting.

BTW. You could replace your editcontig() sub with

my $contigfile = "$contig.txt"; open(CONTIG, $contigfile) or die (">Could not open $contigfile!\n$!"); my $goodseq = <CONTIG>; $goodseq =~ tr[0-9\n ][]d; #clear giant variable to free some memory???? # $rawseq = '';

This will reduce the memory required by your program from 35 MB to around 6MB.

It will also speed it up slightly, but if that offends you, you can always add a sleep 10; :)


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

In reply to Re: substr is behaving differently with small vs large strings by BrowserUk
in thread substr is behaving differently with small vs large strings by wadunn

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.