Hi, this comes close to your suggestion, but it tries to find a match in the lines created before. Don't know if it fits your requirements (see comments). And it can surely be optimised...
use strict; use warnings; my $ref = 'agctagctagctagacatgctagctagctgatcgatgctagctagctgactga +cgacgacat'; my @fragments = qw(agc tagcg agca atgctagctagc acga gcatgc acat tagctg +atcgatgct); my @out; my @nomatch; # what it does *not*: # a) show each occurence of a fragment, e.g. 'acat' # b) separate adjacent fragment, e.g. agc and tagcg will be # seen as agctagcg # c) optimising (minimum number of lines) # d) check that a fragment is a fragment of another fragment # (e.g. "agc" is part of serveral other fragments) outer: foreach my $fragm (@fragments) { my $pos = index($ref,$fragm); push (@nomatch, $fragm), next if ($pos<0); # no match my $len = length($fragm); foreach (@out) { if (substr($_,$pos,$len) =~ /^\s+$/) { # found first empty slot substr($_,$pos,$len) = $fragm; next outer; # done, try next fragm. } } # could not fit fragment -> add it as a new line push @out, ' ' x length($ref); substr($out[-1],$pos,$len) = $fragm; } # and out print "ref: $ref\n"; print "out: ", join("\nout: ", @out), "\n"; print "no match: ", join(", ", @nomatch),"\n";

In reply to Re: formatting output question (use of recursive subroutine?) by Perlbotics
in thread formatting output question (use of recursive subroutine?) by rogerd

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.