in reply to wrapping a pair of lines; what if different lengths?

You'll note that you're only testing against the length of your 0th string, and not the longest one. What you need to do is figure out which is the longest, and test against that.
my $line_length = 60; my @strings = ($genome1, $mismatches, $genome2); # Determine the longest string of the group my $length = (reverse sort { $a <=> $b } map { length } @strings)[0]; # Then iterate through for (my $x = 0; $x < $length; $x += $line_length) { print substr ($strings[$_], $x, $line_length),$/ for (0..2); }
It's not clear what your join/map combination was doing.

Replies are listed 'Best First'.
Re: Re: Wrapping Strings
by Anonymous Monk on Jan 17, 2003 at 11:22 UTC
    thanks for the help! I am writing this to do a cgi and am having problems embedding the html into your code.
    print STDOUT join ("font face=\"courier\"><p>" substr ($strings[$_], $ +x, $line_length), $/ for (0..2)) "</font><p>";
    Can you see where my syntax is bad?? thanks again
      hi

      If you are doing cgi then I suggest that you check out Ovid's "Web Programming Using Perl" Course which is a pretty good intro to CGI programming.

      Might I also point you to Bioperl which is a bioinformatics perl site where lots of common sequence manipulations etc. have already been solved.

      A.A.

      You might not have noticed, but the print command can take a list of things to print, which means that join() is really not required. The syntax error is that after your first string where you establish the font, you don't use the period to concatenate, or a comma to make a proper list.
      foreach (0..2) { print '<font face="courier"><p>', substr($strings[$_], $x, $line_length), '</p></font>', $/; }
      I moved the for-loop into a more obvious location. Before you were losing it in the print statement. I've also take then liberty of opening your <FONT> tag properly, as well as using single quotes to avoid having to escape the quotation marks in your HTML.

      As another note, print sends to STDOUT by default, so there's no real need to specify that.