Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Maximum string length

by turo (Friar)
on Feb 22, 2006 at 19:39 UTC ( [id://532073]=note: print w/replies, xml ) Need Help??


in reply to Maximum string length

hi Berislav,
i think, you have 2 problems on your code:

  1. for ($lb=0; $lb<length $dna; ++$lb), the lenght of the array must be length($dna) -1 (the last elemet cannot be compared with anything ... perl accepts this, though)
  2. the 'tr' only tries to convert between lowercase letters. The example you gave us have uppercase letters ... the result isn't the same ...

I've retouched your script, so the problem of the large string will not affect you
#!/usr/bin/perl -w use strict; system "clear"; print "Palindrome - gamma version\n"; print "--------------------------\n\n"; print "Please enter DNA filename: "; my $filename=<STDIN>; chomp $filename; die "No such file...exiting\n\n" unless (-e $filename); open(DNASEQ, $filename) or die "Cannot open file...exiting\n\n"; my $last_protein; my $count_of_2=0; while (<DNASEQ>) { chomp; my ($lba,$rba)= ($last_protein, undef); for (my $lb = 0; $lb < (length) - 1; ++$lb) { $lba = substr ($_, $lb, 1); $rba = substr ($_, $lb+1, 1); $rba =~ tr/atgcATGC/tacgTACG/; ++$count_of_2 if ($lba eq $rba); } $last_protein = $rba; } print "Number of 2bp palindromes: ", $count_of_2, "\n";

hope that helps :-)

perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://532073]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found