Greetings and Salutations Perl Monks,

My objective is to wrap a SPICE statement string that is greater than 79 characters onto multiple lines. The lines following the first line must be preceeded with a continuation character, a plus (+) sign. For readability purposes the line should be broken on word boundries (whitespace).

I previously found an answer to my question on this site two years ago (for a slightly different problem). I found when I needed to expand this solution to pre-fix the continued lines with a "+"-sign it failed. I'm not sure why it is failing. Here is a snippet of the code. The original code was contributed by Anonymous Monk & Poznick.

$spice_str = "VIN IN VSS PWL ( 0ns 0.0 4ns 2.4 25ns 0.0 50ns 2.4 51ns +0.0 75ns 2.4 76ns 0.0 100ns 2.4 101ns 0.0 )"; $rest = $spice_str; @text = (); while ( $rest ne '' ) { $rest =~ /(.{1,25}[^a-zA-Z0-9.])/ms; push @text, $1; $rest = $'; } foreach ( @text ) { print "$_\n"; }
Works, but if I change it slightly:
$rest = "+ " . $';
It appears to hang, like awaiting input. I realize that I could alter the final print foreach statement to fix this issue, but I wanted to understand what's going on. And, of course, I would like to make this as elegant (and readable by my customer) as possible.

An unworthy Physicist posing as a Perl programmer,

gcmandrake


In reply to Splitting SPICE lines on 'word' boundries closest to a certain length by gcmandrake

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.