in reply to get substring when you know START and END???

Say you have
$seq= 'ABCDEFGHIJKLM';
$start=5;
$end=7;
As I can see, I want to print 'EFG'...
By using substr, I print 'EFGHIJK'.
  • Comment on Re: get substring when you know START and END???

Replies are listed 'Best First'.
Re^2: get substring when you know START and END???
by GrandFather (Saint) on May 27, 2006 at 21:53 UTC

    So you are using 1 based numbering and you need to do the following:

    use strict; use warnings; my $seq= 'ABCDEFGHIJKLM'; my $start=5; my $end=7; print substr $seq, $start - 1, ($end - $start) + 1;

    Prints:

    EFG

    DWIM is Perl's answer to Gödel
Re^2: get substring when you know START and END???
by swampyankee (Parson) on May 27, 2006 at 23:02 UTC

    You've had about 3 people explain to you how to get the length of a string given its start and end points. What more do you need?

    emc

    "Being forced to write comments actually improves code, because it is easier to fix a crock than to explain it. "
    —G. Steele