Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, I am trying to run a perl script that looks at different lengths of sequence. This program works fine with 20000 character string, but when i tried to work with 50000 character string i get this error message:
/(.{50000})/: Quantifier in {,} bigger than 32766
Does anyone know of a way to get around this?? Many thanks, AM

Replies are listed 'Best First'.
Re: string length problems
by Roger (Parson) on Jan 23, 2004 at 10:33 UTC
    Looks like you only want to capture first 50000 characters from the string with the regex, any characters. You could just do a substr:
    my $long_str = 'X' x 100000; my $capture = substr($long_str,0,50000);

Re: string length problems
by larryk (Friar) on Jan 23, 2004 at 10:31 UTC
    Yeah, how about /(.{32766}.{17234})/ ;)
       larryk                                          
    perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
    
      sorry I dont understand. where would I put this line?
        Wherever /(.{50000})/ goes of course (where else).
Re: string length problems
by ysth (Canon) on Jan 23, 2004 at 10:31 UTC
    It's not clear what you are trying to do, but length or substr would probably help.
      This is the line where i split the string at a user defined value ($window).
      $seq =~ s/(.{$window})/$1\n/g;
      who can I split this the same using substr?
        for (my $pos = $window; $pos <= length($seq); $pos += $window+1) { substr($seq, $pos, 0, "\n"); }
        is the least ugly I could come up with.
Re: string length problems
by Skeeve (Parson) on Jan 23, 2004 at 13:59 UTC
    Just found another nice solution:
    $window=79; $str="X" x 723; print join "\n", unpack "A$window" x ((length($str)+$window-1)/$window +), $str;
    String is split by unpack into enough pieces of $window length. "A$window" is the pattern for one piece. This is multiplied by (length($str)+$window-1)/$window.
    the resulting array is then joined with "\n";
Re: string length problems
by Skeeve (Parson) on Jan 23, 2004 at 13:26 UTC
    Maybe a bit less ugly?
    I changed it from 5000 to 79 so that one can view the result.
    $window=79; $i=-1; $str="X" x 723; substr($str,$i,0)="\n" while (($i+=$window+1) < length($str)); print $str;
    This works by inserting "\n" at every $window+1 position.