This newbie got major help from ikegami (++!) in making this question coherent. In fact, the good Friar also came up with an elegant script to achieve the original intent.

BUT, reviewing his work, my mess, the perl documentation, owl, llama, and supersearching... I still am missing something (and very possibly, something very obvious to many of you)... to wit; why doesn't the split /$splBRK/ in &splBRK remove the "~~" in the $aphors?

#! c:/perl/bin -w use strict; # vars use vars qw( $aphor $new @new $max $min $splBRK $rest $subscript); $aphor = ""; # the selected "fortune" $new = ""; # $aphor after $splBRKs are s///to '\n\t' $max = 65; # var for position inside substr at which breaki +ng is more strongly needed than at $min $min = 52; # $min, which is actually used for s/// $splBRK="~~"; # char pair in aphor.asc to mark positions of man +datory newlines (ie, at the end of each # quote in aphor.asc that needs, on rendering, + to be set off with a newline $rest =""; my $aphor1 = "This is a short line ~~ with a splBRK."; my $aphor2 = "Q: How many shrinks does it take to change a lightbulb?~ +~A: One ...but the lightbulb has to want to change."; my $aphor3 = "This is a short line followed by space-dbltilde-space ~~ + This should be printed on a newline."; my $aphor4 = "Test line with double-tilde here~~and more stuff that is + more than var_max chars in length so that we also get a test of the +line splitting after approx 60 characters after which there's some le +ft over."; my $aphor5 = "Variant with space-double-tilde (after the space) ~~and +enuf more chars that the total length is more than var_max chars in l +ength so that we also get a test of the line splitting after approx 6 +0 characters after which there's some left over."; my $aphor6 = "No splBRKs in this: Now is the time for all good men to +come to the aid of their country while the quick red fox jumps over t +he lazy brown dog's back and the fork runs away with the spoon."; my $aphor7 = "This is a short line (but more than min) with no splBRKs +."; # main if ( $ARGV[0] && ( $ARGV[0] > 0 ) && ($ARGV[0] < 8 ) ) { $subscript = $ARGV[0]; print "\nSELECTING \$aphor$subscript \n"; } else { die "No ARGV or ARGV out of range! Useage: perl cli2.pl 1..7"; } if ($subscript == 1) { $aphor = $aphor1 } elsif ($subscript == 2) { $aphor = $aphor2 } elsif ($subscript == 3) { $aphor = $aphor3 } elsif ($subscript == 4) { $aphor = $aphor4 } elsif ($subscript == 5) { $aphor = $aphor5 } elsif ($subscript == 6) { $aphor = $aphor6 } elsif ($subscript == 7) { $aphor = $aphor7 } else { die "ARGV out of range"; # belt & suspenders } if (length($aphor) > ($max+6) || $aphor =~ /~~/ ) { # plus six is a +n ARBITRARY ALLOWED OVERRUN &splBRK; } else { $new = "\n\t" . $aphor; &out; exit(58); }
# sub splBRK -- breaks a line of undefined length by replacing each + $splBRK with a \n\t # # BUT the split /$splBRK/... (with or w/o parens) is NOT removing all + splBRKs # NOR does it work with "/~~/" sted "/$splBRK/" sub splBRK { $_ = $aphor; if (/$splBRK/) { # are there any $splBRK??? print "\n\tFrom sub_splBRK: splBRK found\n"; # DEBUG stmnt } else { print "\n\n\t NO splBRK found\n"; &shortenlines; exit(75); } my @sect = split /$splBRK/; $new= join "\n\t", @sect; &shortenlines; }
# SUB shortenlines -- breaks a line of undefined length by replacing + # a space with a \n at least every $max chars # Match is not yet capable of dealing correctly w/the likes of "...yak +ity yak (blah, blah.)" sub shortenlines { use vars qw($post); $rest = "\n\t" . $aphor; @new = $rest =~ m/\G(.{$min,$max}[\x20.])?/gsx; if ($') { $post=$'; $new[$#new] = $post; } print "\n\n\t----- 100 (after splt and jn) --------\n\n"; foreach my $item (@new) { if ($item) { print "\t$item \n"; } } print "\n\n\t------------------------------------\n\n"; exit(108); } # SUB out # alternate print for short lines w/no splBRKs sub out { print "\n\n\t----- SUB OUT 116---------------------\n\n"; print "$new"; print "\n\n\t ---- DONE: FROM SUB out ---------- \n"; exit(121); }

In reply to unexpected behavior with split by ww

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.