Padre - Perl IDE
Now let's install Padre the Perl IDE to give the students a nice development environment. There are instructions on the website, however,cpanp -i Padre should get the trick done since it is on CPAN In the future Strawberry will ship with Padre but that future isn't quite here.First Program
Ok so we want to make sure that we have Perl installed correctly and since you're taking my advice I'm assuming that you've given your students access to 5.10.1 and may have 5.8 as well... So I'm gonna do this one twice. Have them create a text file hello_world.pl and add the following lines
#!/usr/bin/env perl
print "Hello, World\n";
Since I'm sure this is not your students first programming class this will be familliar to them. Explain the shebang (#!) line and note that it has no effect on windows. Now let's modernize it, using the say feature from perl 5.10.
#!/usr/bin/env perl
use feature 'say';
say "Hello, World";
note the removal of the \n and that use feature is a pragma that allows you to enable features that are newer in perl that weren't available in the original perl 5. Perl is a bit backwards about this, IMO. We should be using the newest version and features unless we specify otherwise, IMO, but that's not how it works, ATM. If 5.10 isn't available to you and your students just use print in future examples. I will be excluding the shebang line from future examples too.Now let's expand hello world a bit. Have them Make it print
Hello, programming!
Here we go!
First thing is to make use of concatenation
use feature 'say';
say "Hello, programming"
. "Here we go";
This example is inspired by Programming: Principles and Practice Using C++. operator is in the front. This draws a programmers attention to it and notes that it's a continuation. See Perl Best PracticesYour output will be.
Hello, programming Here we goThat's not what we want! obviously say appends a newline to the end but doesn't help with long strings.
use feature 'say';
say "Hello, programming\n"
. "Here we go";
Much Better.Simple Game
Now let's up the ante a bit. Again not there first programming class, the following example is rewritten in Perl from Head First Programming: A Learner's Guide to Programming Using the Python Languagenote: you can use < STDIN > but blogger screws it up because of the brackets. This code works exactly the same.
So now you can discuss: scalars, if then else statements,and readline. There are also two additional pragma's strict and warnings that you should tell your students to always use unless they have a 'good' reason to disable them (these have been there since the beginning).
So usually on the first night of class you're lucky to get past hello world. I think this is all doable. In 1 small program I just took you all the way to Chapter 6 in Perl by Example (3rd Edition)
No comments:
Post a Comment
No trolling, profanity, or flame wars :: My Blog, my rules! No crying or arguing about them.