Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello and welcome, aseee.

You posted a rather large amount of code for a broad question. If you can show expected output and tell where exactly you are having trouble it will be much easier to provide a helpful answer. Also, I'd suggest having a look through perlintro and perlstyle. Cleaning up your code a bit will go a long way towards helping us help you. Not to mention, a strong understanding of the basics will better equip you to answer your own questions in the future.


**UPDATE**

Since you didn't exactly point out where your problem lies, I'm going to guess it is most likely in the maze of single char variable names and unformatted loops. I would suggest cleaning up your algorithm subs. The added clarity in conjunction with a slow review may yield the solution to your problem. Also, the Knuth-Morris-Pratt algorithm is covered on page 370 in Mastering Algorithms with Perl by Jarkko Hietaniemi, John Macdonald, and Jon Orwant. There is a link to view this material online in this node Knuth-Morris-Pratt Vs. Perl. I suggest you contemplate rewriting your code using this material as a guide, and implore you to research more thoroughly before asking for help. Finding your own answers is infinitely more rewarding ( I myself learned what the KMP algorithm is and how it works by researching Your question tonight ;).

I took a stab at cleaning up some of your code. Some notes to keep in mind:

Incremented for loops i.e. for ($i = 0; $i <10; $i++) { ... } are easily changed to for (0..9) { ... }

White space can be key in clarity. Try to keep a consistent indentation theme. i.e:

for (0..9) { print "line1\n"; print "line2\n"; if ($cond =~ /pattern/i) { do something; } }

Here is a revised (UNTESTED) sample of your opening for loop.

my @tt=($T_one,$Ta,$rr); foreach my $string (@tt) { @loc=(); @text=(); my $strLength = length($string); my @stringArr = split //, $string; print "<\br>"; print "Length of Gene Sequence Array: $strLength\n"; foreach my $pattern (@patterns){ print knuth_morris_pratt($string, $pattern), "\n"; } @loc = sort {$a <=> $b} @loc; print "</br>"; print "@loc"; print "</br>"; my $i=0; foreach my $k (0 .. ($strLength-1)) { print $i; if ($k == $loc[$i]){ print "<span style=background-color:red;>$text[$k]</span>" +; $i++; } else { print $text[$k]; } } print "</br>"; }


In reply to Re: Pattern Searching by marquezc329
in thread Pattern Searching by aseee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-24 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found