Your skill will accomplishwhat the force of many cannot PerlMonks

by ailie (Friar)
 on Jun 02, 2004 at 17:08 UTC Need Help??

Not long ago I was lucky enough to hear TheDamian's Perligata talk. I suppose you could say it inspired me (one could also say that I have more time than sense) and I decided to try my hand at writing something simple. Those five years of Latin in school have to be good for something, right?

A couple of hours later I had this:

```#!/usr/bin/perl -w
use Lingua::Romana::Perligata;
biguttam tum lacunam egresso scribe.
meo multipliero multiplicamentum
II tum MMMCXLI Mimum da.
meo circumferenceo
multiplicamentum multiplierum
scribe egresso dictum sic
Circumference cis.
biguttam tum lacunam tum
circumferenceum tum novumversum
egresso scribe.

Here's a closer look.

Enter tum radius inquementum tum biguttam tum lacunam egresso scribe. Write to the exit (STDOUT) "Enter" then "radius" then a colon and then a space.

meo radiuso vestibulo perlegementum da. Give to my \$radius the data from the entrance (STDIN).

meo multipliero multiplicamentum II tum MMMCXLI Mimum da. Give to my \$multiplier the product of 2 and 3.14. (Yes, this is inelegant along with the next line - ideally I'd be doing all the multiplication in one go, but I kept running into glitches.)

meo circumferenceo multiplicamentum multiplierum tum radiusum da. Give to my \$circumference the product of \$multiplier and \$radius.

scribe egresso dictum sic Circumference cis. biguttam tum lacunam tum cirfumferenceum tum novumversum egresso scribe. Write to the exit "Circumference" then write also a colon, a space, \$circumference, and a newline. (Again, inelegant - I have two print statements to produce one line, but I was running into trouble with all the tums.)

If you use Lingua::Romana::Perligata 'converte' you can see what the translated back to Perl is.

```print (STDOUT Lingua::Romana::Perligata::__enquote__ ( 'Enter', 'radiu
+s'), ":", " ");
my \$radius  = IO::Handle::getline (*STDIN );
my \$multiplier  =  (2 * 3.141);
my \$circumference  =  (\$multiplier * \$radius);
print (STDOUT 'Circumference');
print (STDOUT ":", " ", \$circumference, "\n")

This is really helpful when writing Perligata.

Did I learn something from this? You bet. Even though my Latin is extremely rusty, thinking about Perl in terms of a spoken (albeit dead) language gave me a new outlook. Plus it looks cool. I also found that the best way to approach writing in Perligata is not to take regular Perl and try to translate it one line at a time, but to actually think in Perligata. (Your milage may vary, of course.)

Stupid Perl tricks:

```#!/usr/bin/perl -w
use Lingua::Romana::Perligata;
biguttam tum lacunam egresso scribe.
meo multipliero multiplicamentum
II tum MMMCXLI Mimum da.
meo circumferenceo
multiplicamentum multiplierum
scribe egresso dictum sic
Circumference cis.
biguttam tum lacunam tum
circumferenceum tum novumversum
egresso scribe.

Version 4:

```#!/usr/bin/perl -w
use strict;
use Date::Simple ('date', 'today', 'ymd');

my %months = (
"jan" => "1",
"feb" => "2",
"mar" => "3",
"apr" => "4",
"may" => "5",
"jun" => "6",
"jul" => "7",
"aug" => "8",
"sep" => "9",
"oct" => "10",
"nov" => "11",
"dec" => "12",
);

my \$year = today()->year;
print "Enter a month and day:\n";
my (\$month1, \$day1) = split /\s+/, <STDIN>;
chomp(\$month1, \$day1);
\$month1 = lc \$month1;
\$month1 = substr(\$month1,0,3);
\$month1 = \$months{\$month1};
print "Enter a month and day:\n";
my (\$month2, \$day2) = split /\s+/, <STDIN>;
chomp(\$month2, \$day2);
\$month2 = lc \$month2;
\$month2 = substr(\$month2,0,3);
\$month2 = \$months{\$month2};
my \$date1 = ymd(\$year, \$month1, \$day1);
my \$date2 = ymd(\$year, \$month2, \$day2);
my \$diff = \$date2 - \$date1;
print "Difference is \$diff.\n";

Version 3:

```#!/usr/bin/perl -w
use strict;
use Date::Simple ('date', 'today', 'ymd');
my \$year = today()->year;
print "Enter the month of the first date:\n";
chomp(my \$month1 = <STDIN>);
print "Enter the day of the first date:\n";
chomp(my \$day1 = <STDIN>);
print "Enter the month of the second date:\n";
chomp(my \$month2 = <STDIN>);
print "Enter the day of th second date:\n";
chomp(my \$day2 = <STDIN>);
my \$date1 = ymd(\$year, \$month1, \$day1);
my \$date2 = ymd(\$year, \$month2, \$day2);
my \$diff = \$date2 - \$date1;
print "Difference is \$diff.\n";

Earlier this summer I was considering taking a programming course and the professor posted a list of self-assessment questions. It turns out that I won't be able to take the class, but I've gotten through all five questions, although one of them has been bothering me.

The original problem was this: Write a program that finds the number of days between two dates in the same year. The user inputs one date, presses the return key, then enters another date. The input is of the form "Month day", for example, Jul 4 or Oct 31.

I'm probably over-analyzing this, but I've been bothered by ambiguities in this problem. Does same year mean same calendar year, or within the same 365-day period? What about leap years?

With this in mind, I decided that limiting it to the same year was not so much fun, so this first version finds the number of days between any two dates. (OK, I'll fess up - I wasn't sure how to get it to do it for the same year using Date::Calc. Now I would like to know.)

Here's my first attempt at the script:

```#!/usr/bin/perl -w
use strict;
use Date::Calc qw( Decode_Date_US Delta_Days );
print "Enter first date in month day year format: \n";
chomp (my \$date1 = <STDIN>);
my (\$year1,\$month1,\$day1) = Decode_Date_US(\$date1);
print "Enter second date in month day year format: \n";
chomp (my \$date2 = <STDIN>);
my (\$year2,\$month2,\$day2) = Decode_Date_US(\$date2);
my \$Dd = Delta_Days(\$year1, \$month1, \$day1, \$year2, \$month2, \$day2);
print "Days between those dates: \$Dd\n";

That's fine and dandy as long as the year is specified, but the problem says same year, so I decided maybe Date::Calc was too much to throw at the problem. The next attempt uses Time::Local and it's fine, except that small details (explained below) nag at me.

```#!/usr/bin/perl -w
use strict;
use Time::Local;
print "Enter the first month:\n";
chomp (my \$m1 = <STDIN>);
print "Enter the first day:\n";
chomp (my \$d1 = <STDIN>);
print "Enter the second month:\n";
chomp (my \$m2 = <STDIN>);
print "Enter the second day:\n";
chomp (my \$d2 = <STDIN>);
my \$y = 2003;
my \$difference = int( (timelocal(0,0,0,\$d1,\$m1,\$y) - timelocal(0,0,0,\$
+d2,\$m2,\$y))/24/60/60 +0.5);
print "\$difference\n";

Small details: this finds the difference in dates between two dates in the same calendar year, but the year has to be hardcoded. Also, the problem asks for the dates to be entered in a certain format. I really like my first solution better, but I want to know the answers to these nagging details.

PM FAQ

-What is PM?
-Who runs it?
-Who uses PM?
-Is PM a good place to get answers for homework?
-PM and JavaScript

Getting Started
-Creating an account on Perl Monks
-Logging on to Perl Monks
-User preferences
-I need help! Who can help me?

Searching PM
-Search
-Super Search

Making a Post on PM
-I want to ask a question of the Perl Monks; where do I start?
-Where do I post?
-What makes a good post?
-Writeup Formatting Tips
-How do I change/delete my post?
-Someone voted my post down - why?

PM Tour (these will be subdivided)
-The Monastery Gates
-Snippets
-Cool Uses for Perl
-Poetry
-Code
-Obfuscation
-Q&A
-Library
-Seekers of Perl Wisdom
-Craft
-Meditations
-Perl Monks Discussion
-Perl News
-Reviews
-Tutorials
-Offering Plate
-Chatterbox (will have its own section as well)
-Poll

The Power Structure of PM
-Level system
-Level powers
-Gods
-Editors (not sure about terminology here)
-Voting/Experience System

PM Nodelets (probably missing some here)
-XP nodelet
-Personal nodelet
-Chatterbox
-Other users
-Sections
-Information
-Poll
-Leftovers

Edification

Personal nodelet by Personal Nodelet Extractor and Restorer
Stats by reputer
Chat by framechat

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-05-27 18:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
World peace can best be achieved by:

Results (195 votes). Check out past polls.

Notices?