Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
If you need to reformat blocks of text with wrapping, I suggest you look at Text:Wrap. The regular expression you have now will over-split short lines:
use strict; my $sequence = "This is a nice line "; # Note: You should use '\1' rather than '$1'. $sequence =~ s/(\S{1,80})/\1\n/g; print "*",$sequence,"*\n";
This prints:
*This is a nice line *
If $sequence contains nothing but solid blocks of non-space characters (genome sequences, for example), or you don't care about splitting short words, then unpack would be faster.
use strict; my $sequence = "123456789012345678901234567890123456789012345678901234 +56789012345678901234567890123456"; my $len = int(length($sequence)/80); my @seq = ($len > 0) ? unpack("(A80)$len A*",$sequence) : $sequence; print "*",join("\n",@seq),"*\n";

In reply to Re^3: Finding error: uninitialized value in concatenation? by tall_man
in thread Finding error: uninitialized value in concatenation? by bwelch

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.