Public Scratchpad | Download, Select Code To D/L |
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; Enter tum radius inquementum tum biguttam tum lacunam egresso scribe. meo radiuso vestibulo perlegementum da. meo multipliero multiplicamentum II tum MMMCXLI Mimum da. meo circumferenceo multiplicamentum multiplierum tum radiusum da. 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; Enter tum radius inquementum tum biguttam tum lacunam egresso scribe. meo radiuso vestibulo perlegementum da. meo multipliero multiplicamentum II tum MMMCXLI Mimum da. meo circumferenceo multiplicamentum multiplierum tum radiusum da. 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
About PM
-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
-Choosing a username
-Changing your password
-Retrieving a forgotten username or password
-Logging on to Perl Monks
-Your home node
-Your user settings
-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?
Linking
-How do I link to nodes on this site by title?
-How do I link to a node on this site by number?
-There is more than one node with the same name, How do I link to the one that I want?
-Linking to Modules on CPAN
-How can I link to a Google search without using the actual URL?
-Can I link to a book by ISBN?
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
-Newest Nodes
-Offering Plate
-Chatterbox (will have its own section as well)
-Poll
-Scratch Pad
Chatterbox
-What is the Chatterbox?
-is the chatterbox logged?
-Using the Chatterbox: Public Messaging
-Using the Chatterbox: Private Messaging
-Using the Chatterbox: URLs, Special Characters, and Code
-Using the Chatterbox: Linking
-What other clients can I use for the Chatterbox?
-What does SoPW mean? (or Guide to Perl Monks Abbreviations)
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
-Your input
-Poll
-Leftovers
ybiC's links
Question-asking
- What makes a bad question?
- How to ask questions the smart way.
- Homework and the Monastery
- New Monks Info Page
- New Monks
- Link to Perl Monks FAQ in Information Nodelet
- How to RTFM
- How to get the most of your question from the monks
- Writeup Guidelines
- On asking for help
- PerlMonks Commandments (was: Seven Deadly Sins)
- Chapter 714: The Long Chapter
- Development of the Perl Monks Code of Conduct
- From Initiate to Monk
- Before You Post ...
- Chip (on the shoulder) Monks
- In defense of civility
- In defense of criticism
- Turnstep's tips & tricks
Chatterbox
- Chatterbox FAQ
- New green theme and /ignore for private messages
- Curses Chatterbox Client
- cblast35
- pmchat
- monkyack.pl
- New Message Inbox Feature
- Regarding the Chatterbox
- alternative framechat
- framechat2
- framechat
- RedWolf MonkChatter
- chatterbox frameset improvements
- Message Inbox
- New chatterbox features
- Chatterbox stats
- Chatterbox Improvements
- Eulogy for the chatterbox
- (zdog) RE: Two links, and a name.
- Chatterbox abuse and possible remedies
- Get chatbox lines
- E-mail Node
- ZZamboni
Linking and tags
- New Link Tags
- READMORE tag in notes
- Nifty New Feature
- More Linking Conventions For ya
- I pity da foo who forgets to add a title
- Now you too can add Read More Links to root nodes
- Perl Monks Approved HTML tags
- Linking Convention Improvements
Levels responsibilities
- Reminders for Friars, etc...
- Considering duplicates
- Responsibilities re Unapproved Posts
- When to frontpage a node?
- Change to consideration feature
- New site editors
- Care and Discretion
- Considerations of Nodes To Consider
- NodeReaper loose in the monastery
- Handling Nodes Worthy of Deletion which contain replies
- Nodes to consider changes
- SOPWIFY!! for QandAEditors
- Considering nodes to consider
- Consider this node feature
- Moving writeups between sections
- Friar
- SiteDocClan
- (OBE) Moderation and Editing Info
- QandAEditors
- How to use the moderation system (if you're level 6)
- how to use the moderation system
- Editor requests
Site change
- Complete and Unabridged Site Changelog
- New ticker login for PM XML clients
- Turn JavaScript off on HomeNodes
- Monks and Mongers
- New user scratch pad.
- pmdev user group
- State of the Monastery or an attempt to clear up at least some confusion
- All your Votebots are belong to us
- PM + YAS = ?
- New Power Proposal
- Changelog Node?
- new tag
- DisplayType Raw
- PerlMonks Offering plate now available
- Is PerlMonks economically viable?
- Which modules are most often mentioned on PerlMonks???
- The True Catacombs of Perlmonks
- Super search gets a little bit more super
- Secret Search
- New Site Documentation Source
- Personal Node Order
- New Everything Developer Nodelet
- Beginning of some quality documentation... hopefully
- Upcoming survey to help me better the site
- (ar0n: code) RE (2): Newest Nodes too big?
- More tasty XML goodness
- Newest Nodes XML Generator
- Personal Nodelet change
- New Keyword Functionality
- Home Node Image
- We've missed you at Perl Monks
- Monks by Writeup Count
- Useragent Logs
Voting and reputation
- Challenging votes
- Reasons for downvoting
- Voting nodes: I've had enough
- On Voting
- Choose a maximum for Rep
- Votes in the pool
- The fickleness of Reputation
- Level Proposal
- An Anonymous Vote
- time for new highs?
- Vote, talk, any post invalidates next entries links
- Suggestion/Requests.
- New level - Demigod
- X-treme P-ondering
- Proposed XP System Changes
- prevent votes on anonymous posts
- ? why do you vote like you do ?
- How can this be?
- Higher level posts ;
- (OBE) Voting/Experience Information
- Scalability of the voting system
- Level Powers
- Future user levels
PM-related stats & sundry
- Best Nodes
- Worst Nodes
- More Stats...
- jcwren's PM stats
- jcwren's web hosting for monks
- Web Hosting For Monks - News Update
- Web Hosting for Monks - Gone Live!
- (jcwren) RE: Monks' Maps!
PM-related code not in Code Catacombs
- Personal PerlMonks Stats plot creator
- Re: Personal Monk Stats plot creator (xrepwalker patch)
- Stats Whoring - The VXML Way
- Perlmonks Related Scripts
- PerlMonks search HTML snippet (non-Perl)
- drawmap.pl - Spot The Monk!
- Insert Language Here Monks
- Random NonHome Nodes
- bivnn.cgi -- an alternate interface to newest nodes
- Graph displaying reputation of all your nodes
notable PM-related discussions
- So it's homework - so what?
- PM Login Problems
- Learn to be a pmdev vigilante in 21 days!
- Fun with PerlMonks and CSS
- Rampant Frontpaging
- Name Space
- RFC: flagging solutions...
- this place should define a relation to CPAN soon
- I dont need your politics any more. (discussion)
- Keep myself off PerlMonks
- /away CB command?
- Old, unused nick desired..
- Golf Do-s and Don't-s
- Earthquakes & Perlmonks
Education
- Helping out with offsite links
- Stubborn as a Saint
- Virtual Distributed Library Online
- Smokers anyone?
- Diffusing Knowledge and Fortune to the Less Wise and Less Fortunate Monks.
- Perl Books to buy ;
- Addendum to reading list
- On the matter of Books
- Perl Books
- RE (tilly) 3: redeclaring variables with 'my'
- Re (tilly) 2 (disagree): Another commenting question,
- Re (tilly) 1: How to write long programms?
- Random thoughts on programming
- 21st Century Scripting
- How do I become a good programmer?
- Coming up with code design
- Re (tilly) 1: Why Use Perl?
- comments on commenting
- use CGI or die;
- Common Beginner Mistakes
- Ovid's CGI course
- Perl Comencement for the 2000 Class
- Common Regex Gotchas
- Subroutines/Functions:
Entertainment
- Cheesy Web Ring
- Management-speak generator
- Code::Police
- I Know What I Like (In Your Namespace)
- The Perl Film Festival
- (Kidding) XP-whoring HOW-TO
- Tie::Hash::Cannabinol
- Inline::PERL
- Acme::Translator
- Perl cures potty-mouths (SOAP not-withstanding)
- BOfH Random Excuse Generator
- PM Drinking Game
- Confessional
- Merlyn's secret uncovered!
- CRSC
- Re: Re: Reeling In The Years
- My Story
- (crazyinsomniac) Re: Perl Soap
- Iron Perl Monks, Part 1
- Life at the Monastery Chapter 2
- Life at the Monastery. Chapter 1
- I just want to siiiing!
- Perl: Survival of the Fittest
- COBOL vs. Perl
Edification
- A page from the PM book of prayer
- What if God were one of us?
- If God wrote a Perl script
- Love for a Camel
- PSALM 23
Homenode and scratchpad by hup
Personal nodelet by Personal Nodelet Extractor and Restorer
Stats by reputer
Chat by framechat