This document is intended to give you a quick overview of the Perl pro- gramming language, along with pointers to further documentation. It is intended as a "bootstrap" guide for those who are new to the language, and pro- vides just enough information for you to be able to read other peoples' Perl and under- stand roughly what it's doing, or write your own simple scripts. This introductory document does not aim to be complete. It does not even aim to be entirely accurate. In some cases perfection has been sacrificed in the goal of getting the general idea across. You are *strongly* advised to follow this introduction with more information from the full Perl manual, the table of contents to which can be found in perltoc. #### #!/usr/bin/perl BEGIN {(*STDERR = *STDOUT) || die;} use diagnostics; use warnings; use strict; $| = 1; use Text::Autoformat qw(autoformat break_TeX); #-------------------------------------------- # Configuration # Since vertical spacing is fixed (meaning we do not have # the option, at least in this release, of using double # spaced or 1.5 spaced lines) all computation is done in # units of vertical spacing. So we need the width to # height ratio. my $width_to_height = 5/9; # End configuration #-------------------------------------------- my $iterations_limit = 10; my $pi = 3.1412; my %taf_options = ( left => 1, #right => $width, justify => 'full', break => break_TeX, #case => 'sentence ', #widow => 1, ); my @messages = (); push @messages, < $slab_widths[0]) { $adjust += $adjust_increment; @lines = (); $message = $original_message; @lines = extract_top_down($original_message, $adjust, 1, \@slab_widths); $message = $lines[-1]; chomp $message; if($adjust >= $iterations_limit) { $adjust = 1; $adjust_increment = -1; } if($adjust <= -$iterations_limit) { last; } $pedastal and last; } align_tuit(\@lines); print "\nThe tuit as is after $adjust adjusts:\n"; print @lines, "\n\n"; } sub message_as_line { my $message = shift; $message =~ s/^\s+//gm; $message =~ s/\s+$//gm; $message =~ s/-\n//g; $message =~ s/\n/ /g; $message =~ s/\s\s+/ /g; return $message; } sub quantify_circle { my $message = shift; my $count = () = $message =~ m/./g; my $area = $count * $width_to_height; my $radius = sqrt ($area / $pi); my @slab_widths = (); for (- int $radius .. -1) { push @slab_widths, int (2 * (sqrt (($radius * $radius) - ($_ * $_)))/$width_to_height + 0.5); } push @slab_widths, (int ($radius * 2 / $width_to_height + 0.5)), reverse @slab_widths; if(0) { my $check = int ($radius * 2 / $width_to_height + 0.5); for (@slab_widths) { $check += 2 * $_; } my $layers = int $radius; print "count:$count, area:$area, radius:$radius, layers=$layers, check=$check,\n"; print "slab widths:\n@slab_widths,\n"; } return $radius, @slab_widths; } sub extract_top_down { my ($message, $adjust, $widow, $slabs) = @_; # following overrides the global one my %taf_options = ( left => 1, #right => $width, justify => 'full', break => break_TeX, #case => 'sentence ', widow => 1, ); my @lines = (); for my $width (@{$slabs}) { my $foo = $width + $adjust; $foo > 0 or $foo = 2; $taf_options{right} = $foo; ($widow) and $taf_options{widow} = $foo - 1; my $formatted = autoformat $message, {%taf_options}; if(!($formatted =~ s/^([^\n]+\n)(.+\n)$/$2/s)) { $message = $formatted; last; } push @lines, $1; $message = message_as_line($formatted); } push @lines, "$message\n"; return @lines; } sub align_tuit { my $lines = shift; for (@{$lines}) { $_ = " "x(40 - 0.5 * length($_)) . $_; } } __END__ #### The tuit as is after 1 adjusts: It's been said ever so often by many an expert that in ol' plain text one neer can get a round tuit, but just look here The tuit as is after 1 adjusts: This docu- ment is intended to give you a quick overview of the Perl programming lan- guage, along with pointers to further documentation. It is intend- ed as a "bootstrap" guide for those who are new to the language, and pro- vides just enough information for you to be able to read other peoples' Perl and understand roughly what it's doing, or write your own simple scripts. This intro- ductory document does not aim to be com- plete. It does not even aim to be entire- ly accurate. In some cases perfection has been sacrificed in the goal of get- ting the general idea across. You are *strongly* advised to follow this introduction with more informa- tion from the full Perl manu- al, the table of contents to which can be found in perltoc.