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.
Works, but if I change it slightly:$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"; }
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.$rest = "+ " . $';
An unworthy Physicist posing as a Perl programmer,
gcmandrake
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |