![]() |
|
good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Lingua::Romana::Perligata - Basica Basicum Basicusby benn (Vicar) |
on Apr 28, 2003 at 19:12 UTC ( [id://253797]=perltutorial: print w/replies, xml ) | Need Help?? |
Intro Lingua::What? How? Why? Nope - still why? Word order is important in most programming languages too - $x = $y being rather different to $y = $x (I know - we've all been there...). Wouldn't it be nice if that particular 'bug' never cropped up again? If you could say "$x is to be acted upon by $y" or "$y is to act upon $x" - the way you already can in perl with if $x {foo} and foo if $x? As for the aesthetics...well, IMHO, this exemplifies the aesthetics of perl itself. And if that's not enough for all you youngsters out there, then how about "*Man!* You can write a CGI script in *Latin* and show it to all your friends? Just How Cool Is That?". Groovy. Sold - so How, again? Now...Latin also uses inflection to determine the role of the word - for instance, whether it is "doing" (the 'subject') , or "having done to" (the 'object').
"Puer" (boy), is the subject of the sentence - the one that was doing the giving, so it takes no ending. "esca" (food), becomes "escam", as it's the direct object - the thing that is being given. The "canis" (dog) drops the 's' to become the indirect object - the thing that is being given to. If the dog gave some food back, it would be "Canis puero escam dedit"- the 'o' denoting that the boy is now the indirect object. Before you start sweating - don't worry. Although Latin is the uber-grammar language, and has been known to make small boys wet themselves rather than attempt to decline "to beat soundly", you'll only need to learn a few of these endings to write L::R::P. Enough with the theory already - show me some code. Literally translated, that comes out as.."Write to the Exit the result of saying (as follows) Hello world (to here).". Or, more loosely, "print STDOUT q{Hello World};". Note that it ends, as in English, with a period rather than a semi-colon. L::R::P doesn't like anything except alphanumerics and periods - all sigils are completely out of the egresso. Taking that apart, we get "scribe" (print - that's an easy one we still use in English) , "egresso" (STDOUT, literally 'the exit') , "dictum" (like 'dictate' - a quote operator) and the 'brackets' "sic" and "cis" ('as follows' and 'to here' - almost too good to be true...). Even if you're not thinking about writing any code, check out the THESAURUS PERLIGATUS in the POD just for a laugh at the translations - my favourites are STDERR ('oraculo' - a place where doom is pronounced) and rmdir ('excide', or raze, as in '...to the ground'). (Actually, the more usual way of saying this would be... Hello tum World inquementum scribe egresso. ...or "print the result of saying Hello then World" but that particular example doesn't work. Hiya tum World ... is OK though, for reasons to be explained shortly.) Without further ado, let's get straight to... Variables (or "meo varo VIII da." if you're using strict - guess what 'meo' is :) "da" is "=" ('to give'). "var", as the indirect object (the thing being given to - remember?) takes an 'o' to become "varo". And it's being given 'VIII' - yup - even the numbers are in Latin. For 1-10, you can use some names as well - 'unum', 'duo', 'tres' etc. , and zero is "nullum". When it comes to printing it out, on the other hand, 'var' is now an rvalue (rather than the lvalue it was when it was being assigned to), and is the subject of the 'print' verb, so... ...and that's basically how the trick is done. That's why you can say either"scribe egresso varum" or "varum scribe egresso" - "um" denotes that it can only be used as an rvalue, so under the hood, "print" knows that the "whatever-um" next to it is to be printed ( as opposed to the "eggress-o", which it's doing the printing *to*, and which BTW is why 'Hello' as a 'bareword' gets translated to '$Hell'). "varum scribe egresso", "scribe egresso varum", "egresso scribe varum", "scribe varum egresso", "varum egresso scribe", "egresso varum scribe". All the combinations. They all work. Isn't that lovely? That's scalars - arrays and hashes are similar, except they use a couple of different plural forms (as perl uses '@' or '%') to distinguish them from $ingulars. Romani ite Damian's Domum. ) So, we get this... 'tum' ('and then') is a comma, so we have "give 1 then 2 then 3 to the array". If you got this far, you don't need me any more - get straight to the manual and start coding. Remember about 'converte', 'discribe' and 'investiga' - you'll find them very useful. Any suggestions regarding further material to add to this tutorial (or places where I've got it plain wrong) as ever welcome. Thanks to ybiC for the obligatory Monty Python link. Ben
Back to
Tutorials
|
|