Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Welcome to the Monastery!

Please pay attention to the posting rules, especially the one about enclosing your code in ... tags. It makes the code much easier to read, which results in more people wanting to help you.

First for a line by line comment on you code the way you wrote it...

# use strict; # use warnings;

Um... you commented out use strict and use warnings? That's like telling the compiler "I don't need your help! I know what I'm doing! I'm certain!". Leave them in and fix the errors that show up. For instance...

open(READ,"<dna.txt"); @e = <READ>; $a = join( " ", @e );

should be...

open(READ,"<dna.txt"); my @e = <READ>; my $a = join( " ", @e );

Use strict requires that every variable be declared with my (or with "our" or "state" in more complicated cases.)

To fix the coloring, while still following your original logic, I would change

for ( $i = 0 ; $i < length($a) ; $i++ ) { $d = substr( $a, $i, 6 ); if ( $d eq "AGGGGG" ) { print color 'bold green'; $s++; push( @c, $i + 1 ); } } print $a ;

to something like

my $printed = 0; for ( my $i = 0 ; $i < length($a) ; $i++ ) { my $d = substr( $a, $i, 6 ); if ( $d eq "AGGGGG" ) { print substr( $a, $printed, $i - $printed ), color( 'bold green' ), $d, color( 'black' ); $printed = $i + 6; $s++; push( @c, $i + 1 ); } } print substr( $a, $printed ), "\n";

I am printing out the section before each match, switching to green, printing the match, then switching back to black (it doesn't do that automatically.) Note the extra $printed variable is there to keep track of where the last match ended.

Finally,

print "AND THE POSITION IN THE STRING IS:", print join( ',', ( @c, "\n +" ) ), "\n\n";

should be

print "AND THE POSITIONS IN THE STRING ARE:", join( ',', @c ), "\n\n";

which fixes two problems; one is an extra comma after the position of the last match, because join was putting a comma between the last element of @c and the "\n". The second is that it was printing an extra "1". That's because the second print was interpreted as a function call. The print function works like the print statement but it also returns a value, usually 1 to indicate that it worked.


In reply to Re: motif finding by quester
in thread motif finding by devi

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (12)
    As of 2014-07-23 16:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (146 votes), past polls