|
Perl 6
Perl 6 Tutorial Part 1: Revision 12
Motivation for a new TutorialPerl 6 appears slowly before the wondering eyes of the curious, but if they grab Rakudo and the dokumentation (aka synopses) and try to write there first programs, they often don't get too far. The languages changes a bit every week and Rakudo nor Pugs know every command. The synopses aren't an easy read either. They are huge and contain a lot of nifty words. More written to clear edge cases to computer science students than to help the noobs to get a grasp. Therefore we would need a tutorial that introduces the reader slowly into the world of Perl 6 and prerequests as little knowledge as possible. Of course some basic Perl 5 wisdom is needed but everything else will be explained on the way. Every chapter of this tutorial is focused on one topic and containes many examples so you can start to play with the language, which I encourage you to do. Because it takes time to lern Perl and the new generation is optimized even on that. Hello Perl 6Fast jede Einführung in eine Programmiersprache beginnt mit einem "Hello World". Auch wenn ich mir eigentlich was originelleres ausdenken wollte, bleibt es doch das kleinste Programm, das etwas erfreulich sichtbares tut, also starten wir auf ausgetretenen?, nein bewährten Pfaden: say "Greetings, earthlings, err Perl 6 neophytes."; Dieses erste Programm gibt doch tatsächlich den genannten Text aus. Der Befehl say entspricht dem bekannten print, fügt aber noch ans Ende der Ausgabe einen Zeilenumbruch an, der dem Standard des aktuellen Betriebssystems entspricht. Klar gibt es 'print' weiterhin, aber zur Gewöhnung wird ab jetzt say verwendet. Ich kann aber bereits die Einwände der erfahreneren Perlschreiber hören: Ein gutes Skript beginnt mit strict und warnings. Und recht haben sie. In Perl 5 müsste das kleine Programm lauten: Perl 5:
use strict; print "Seid gegrüßt, ihr Perl 6 Programmierer.\n";
Aber in Perl 6 entfällt das, weil beide Pragmas jetzt standardmäßig aktiviert sind. Das spart nicht nur die 2 Zeilen Code, die in fast allen meiner Programme sind, sondern es hilft jenen, die nichts darüber wissen, potenzielle Probleme eher zu sehen. Bei Bedarf kann ja beides, wie bekannt, mit no strict; und no warnings; abschaltet werden. |