#!/usr/bin/env perl # Sample usage: man sh | jack.pl # jack.pl -c -j jack.pl # (Based on jack.c by Jamie Zawinski.) use strict; my( $text, $keep, $work ); $text = "All work and no play makes Jack a dull boy. "; $keep = qr<\t>; while( 1 ) { $ARGV[0] =~ /-c/ and do { $keep = qr<[][;#(){}"]|/\*|\*/|//>; shift; next; }; $ARGV[0] =~ /-j/ and do { $text = "Just another Perl hacker. "; shift; next; }; last; } while( <> ) { # Stupid `man` formatting s/.\10//g; s/[^[:space:][:graph:]]//gs; # Expand tabs 1 while s/\t+/' ' x (length($&)*8 - length($`)%8)/e; xify( split /($keep|(?:\A|\z|\s){4,})/s ) } sub xify { print rep( shift ), shift while @_ } sub rep { my( $len, $s, @s, $i ); $s = shift; return "" unless $len = length $s; ($s, $work) = ($work . $text x (1 + (length($s) - length $work) / +length $text)) =~ m/^(.{0,@{[length $s]}})(?=\s|\A|\z)\s*(.*)/s; @s = split /\s(?=\S)/, $s; return $s . ' ' x ($len - length $s) if @s < 2; $s[-1] =~ s/\s+$//; for( @s ) { $len -= length $_ } for( $i = 0; $len--; $i = ($i+1) % $#s ) { $s[$i] .= ' ' } join "", @s }

In reply to All work and no play makes Jack a dull boy by kaif

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.