# my $len= 79; my $len= 9; # my $esc= '\e'; my $esc= '@'; my $eseq= qr[$esc[^a-zA-Z]*[a-zA-Z]]; my $char= qr[(?:$eseq)*[^$esc\n]]; my $nonsp= qr[(?:$eseq)*[^$esc\s]]; local( $/ )= ''; # Paragraph mode while( ) { print "Wrapping:\n$_"; { local( $_ )= $_; s[(?:^|(?<=\s))((?:$char){1,$len}(?:$eseq)*)\s][$1\n]g; # print "Loose code1:\n$_"; s[(?:^|(?<=\s))((?:$nonsp){$len}(?:$eseq)*)(?=[^$esc\s])][$1\n]g; print "Loose code:\n$_"; } s[(?:\G|^)((?:$char){1,$len}(?:$eseq)*)\s][$1\n]gm; # ^^^^ ^ # print "Tight code1:\n$_"; # vv s[(?:\G|(?<=\s))((?:$nonsp){$len}(?:$eseq)*)(?=[^$esc\s])][$1\n]g; print "Tight code:\n$_"; } __END__ @[0;7mCoruscate@[0m says this is a test of the line wrapping code @[0;7mtye@[0m says this is a test @[0;7mtye@[0m says ThisIsATestOfTheEmergencyBroadcastSystemIfThisHadBeenAnActualEmergency... @[0;7mCoruscate@[0m says this is a test of the line wrapping code @[0;7mCoruscate@[0m says it works! @[0;7mtye@[0m says this is a test @[0;7mtye@[0m says ThisIsATestOfTheEmergencyBroadcastSystemIfThisHadBeenAnActualEmergency... ThisIsATestOfTheEmergencyBroadcastSystemIfThisHadBeenAnActualEmergency... #### Wrapping: @[0;7mCoruscate@[0m says this is a test of the line wrapping code Loose code: @[0;7mCoruscate@[0m says this is a test of the line wrapping code Tight code: @[0;7mCoruscate@[0m says this is a test of the line wrapping code Wrapping: @[0;7mtye@[0m says this is a test Loose code: @[0;7mtye@[0m says this is a test Tight code: @[0;7mtye@[0m says this is a test Wrapping: @[0;7mtye@[0m says ThisIsATestOfTheEmergencyBroadcastSystemIfThisHadBeenAnActualEmergency... Loose code: @[0;7mtye@[0m says ThisIsATe stOfTheEmergencyBroadcastSystemIfThisHadBeenAnActualEmergency... Tight code: @[0;7mtye@[0m says ThisIsATe stOfTheEm ergencyBr oadcastSy stemIfThi sHadBeenA nActualEm ergency.. . Wrapping: @[0;7mCoruscate@[0m says this is a test of the line wrapping code @[0;7mCoruscate@[0m says it works! @[0;7mtye@[0m says this is a test @[0;7mtye@[0m says ThisIsATestOfTheEmergencyBroadcastSystemIfThisHadBeenAnActualEmergency... Loose code: @[0;7mCoruscate@[0m says this is a test of the line wrapping code @[0;7mCoruscate@[0m says it works! @[0;7mtye@[0m says this is a test @[0;7mtye@[0m says ThisIsATe stOfTheEmergencyBroadcastSystemIfThisHadBeenAnActualEmergency... Tight code: @[0;7mCoruscate@[0m says this is a test of the line wrapping code @[0;7mCoruscate@[0m says it works! @[0;7mtye@[0m says this is a test @[0;7mtye@[0m says ThisIsATe stOfTheEm ergencyBr oadcastSy stemIfThi sHadBeenA nActualEm ergency.. . Wrapping: ThisIsATestOfTheEmergencyBroadcastSystemIfThisHadBeenAnActualEmergency... Loose code: ThisIsATe stOfTheEmergencyBroadcastSystemIfThisHadBeenAnActualEmergency... Tight code: ThisIsATe stOfTheEm ergencyBr oadcastSy stemIfThi sHadBeenA nActualEm ergency.. .