This counts along the string and inserts line breaks at regular intervals

#!/usr/bin/perl use strict; use warnings; use CGI; my $WIDTH = 40; my %hash = ( 'name1' => "ATATTATCCCCCTATATATGGAGGGAGAGGGGGGGGGGGGGGGGGGGGGGGGGGGAG +AGAGGAGATTTTTTTTTTTTTTTT", 'name2' => "ATATATTATATATATTATATTCGCGCGCGCGGCGCGCGCGGCGCGCGCGTTTTTTTT +TTTTTTAGGAGAGAGAGGGAGGAGGAGAGGGGAGT", ); my @select=(); my %pattern = ( 'AGGAG' => 'sd', 'TTTTTTT' => 'terminator' ); my $re = join '|',keys %pattern; # add markup foreach my $key (sort keys %hash) { if ($hash{$key} =~ s!($re)!<span class="$pattern{$1}">$1</span>!g){ push @select,$key; } } # create table my $table = q!<table width="100" cellpadding="5" cellspacing="5"> <tr style="font-style:italic"> <td width="20%">Key</td> <td width="5%">&nbsp;</td> <td width="75%">Sequence</td> </tr>!; # selected keys foreach my $key (@select) { my $seq = $hash{$key}; # count ACTG character to determine # position to insert line breaks my $count = 0; my @br; for my $p (0..length($seq)-1){ ++$count if substr($seq,$p,1) =~ /[ACTG]/; if ($count > $WIDTH){ push @br,$p; $count = 1; }; } # insert line breaks working backwards for my $p (reverse @br){ substr($seq,$p,0,'<br/>'); } # create row my $radio = qq!<input type="radio" name="selected_intergenic" value= +"$key"/>!; $table .= qq!<tr valign="top"> <td>$key</td> <td>$radio</td> <td>$seq</td></tr>!; } $table .= q!</table>!; # html page my $q = CGI->new; my $style = <<EOF; body { background: lightgrey; color: black; font-family: Courier; margin:20px; } h1 { color: black; font-family: Verdana; font-size: 150%; } h2 { color:red; font-family: Courier; } .sd { color:red; } .terminator { color: royalblue; } EOF my $note = qq!Sequences with <span class="sd"> SD sequence</span> or <span class="terminator">terminator structure</span>!; print $q->header, $q->start_html(-style=>{'code'=>$style}), $q->h1( $note ), $table, $q->end_html;
poj

In reply to Re: Print N characters per line in Cgi Script with Html Tags by poj
in thread Print N characters per line in Cgi Script with Html Tags by Diesel

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.