Created
January 3, 2013 03:55
-
-
Save zmughal/4440632 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Text::Autoformat; | |
use File::Which; | |
$/ = ''; | |
my $WIDTH = 72; | |
which('figlet') && which('boxes') or die '{figlet,boxes} programs required'; | |
while(<>) { | |
my $par = $_; | |
my $first_char = substr $par, 0, 1; | |
substr($par, 0, 1) = ""; # remove first character | |
my $initial = `figlet $first_char | boxes`; | |
my $initial_width = (index $initial, "\n") + 1; | |
my $lines = () = $initial =~ /\|$/mg; | |
my $remaining_width = $WIDTH - $initial_width; | |
my $formatted = autoformat $par, { justify => 'full', left => 1, right => $remaining_width }; | |
my @split_lines = split /\n/, $formatted, $lines+1; | |
my $last_line_for_initial = $#split_lines < $lines ? $#split_lines - 1 : $lines - 1; | |
for my $line (0..$last_line_for_initial) { | |
$initial =~ s/\|$/| $split_lines[$line]/m; | |
} | |
my $rest; | |
if($last_line_for_initial < @split_lines) { | |
$rest = autoformat $split_lines[-1], { justify => 'full', left => 1, right => $WIDTH }; | |
} | |
print "$initial"; | |
print "$rest" if $rest; | |
} | |
__END__ | |
================================= | |
Input: | |
#!/bin/sh | |
ascii-initial <<EOF | |
Fellow programmer, greetings! You are reading a letter which will bring | |
you luck and good fortune. Just mail (or UUCP) ten copies of this letter | |
to ten of your friends. Before you make the copies, send a chip or | |
other bit of hardware, and 100 lines of 'C' code to the first person on the | |
list given at the bottom of this letter. Then delete their name and add | |
yours to the bottom of the list. | |
Don't break the chain! Make the copy within 48 hours. Gerald R. of San | |
Diego failed to send out his ten copies and woke the next morning to find | |
his job description changed to "COBOL programmer." Fred A. of New York sent | |
out his ten copies and within a month had enough hardware and software to | |
build a Cray dedicated to playing Zork. Martha H. of Chicago laughed at | |
this letter and broke the chain. Shortly thereafter, a fire broke out in | |
her terminal and she now spends her days writing documentation for IBM PC's. | |
Don't break the chain! Send out your ten copies today! | |
EOF | |
================================= | |
Output: | |
----------- | |
| _____ | ellow programmer, greetings! You are reading a letter which | |
| | ___| | will bring you luck and good fortune. Just mail (or UUCP) | |
| | |_ | ten copies of this letter to ten of your friends. Before you | |
| | _| | make the copies, send a chip or other bit of hardware, and | |
| |_| | 100 lines of 'C' code to the first person on the list given | |
| | at the bottom of this letter. Then delete their name and add | |
----------- | |
yours to the bottom of the list. | |
----------- | |
| ____ | on't break the chain! Make the copy within 48 hours. Gerald | |
| | _ \ | R. of San Diego failed to send out his ten copies and woke | |
| | | | | | the next morning to find his job description changed to | |
| | |_| | | "COBOL programmer." Fred A. of New York sent out his ten | |
| |____/ | copies and within a month had enough hardware and software | |
| | to build a Cray dedicated to playing Zork. Martha H. of | |
----------- | |
Chicago laughed at this letter and broke the chain. Shortly thereafter, | |
a fire broke out in her terminal and she now spends her days writing | |
documentation for IBM PC's. | |
----------- | |
| ____ | on't break the chain! Send out your ten copies today! | |
| | _ \ | | |
| | | | | | | |
| | |_| | | | |
| |____/ | | |
| | | |
----------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment