Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Requesting suggestions for one day Perl course

by talexb (Canon)
on Feb 29, 2004 at 20:35 UTC ( #332692=perlmeditation: print w/replies, xml ) Need Help??

I have been asked to present a day long seminar on Perl to a group of first and second year college students in the Software Engineering Technologist program. Since my current employer provides an XML from PDF conversion service, the instructor has also suggested I touch on XML in my seminar.

I can probably put together the Perl part of the course OK -- these folks have some experience with C++ so they'll pick up on the conditionals and loops right away. However, if you have suggestions for the five or six things(1) I should teach C++ programmers interested in learning Perl, as well as one or two cool things that I can show them in XML, let me know.

Alex / talexb / Toronto

Life is short: get busy!

1. You could suggest 'things' like hashes and signal handling, or you could mention 'meta-things' like auto-vivification, one-liners, CPAN, golf/obfu. All suggestions welcome.

  • Comment on Requesting suggestions for one day Perl course

Replies are listed 'Best First'.
Re: Requesting suggestions for one day Perl course
by tachyon (Chancellor) on Feb 29, 2004 at 21:12 UTC

    If they have some C++ you could probably just have a quick bit that covers the 3 basic data types $ @ % and then notes you almost always need ( ) { } and ; for syntax. Much of perls syntax is quite like C so you can probably skip the details and dive right in.

    I would tell them they need to use strict, use warnings and that they declare vars with my and vars scope as expected.

    They need to know how to execute a program so I would probably show them something like:

    #!/usr/bin/perl -w use strict; my $str = 'World'; print "Hello $str\n"; print 'Hello $str\n";

    A traditional starter and shows a few things including the difference in perl between ' and " which generally bites everyone new to Perl.

    A usesful widget for all programmers is find and replace, as is a full RE grep (especially on Win32 which is what they will probably be most familiar with). So you could show them a couple of simple one liners like:

    # inplace edit with backup perl -pi.bak -e 's/this/that/' ./somefiles* # perl grep perl -ne 'print "$.\t$_" if m/some_re/' ./file.txt

    This lets you give them something they can use in day to day coding, and a chance to mention REs and $_ default behaviour and slip in a mention that perl has all sorts of wierd $. type vars.

    Then I would just dive straight into CPAN, as in physically go their download and compile a module or two.

    Then show them how to use a few of the more important modules to make complex tasks into 10 line perl scripts. LWP::Simple and LWP::UserAgent let you demo extreme simplicity and then OO syntax. I will also let you get some XML from somewhere. You could perhaps show off a 6 line IO::Socket::INET function to introduce subs and show how simple socket programming can be in Perl. You could use this to get the XML as well. Then just do something with XML::Simple and do a bit of data munging on it. Perhaps if you have time you could connect to a database with DBI and store and retrieve some of the data you munged from your XML.

    For debugging I would mention use diagnostics, $DEBUG && print "\$var1 is $var1 here\n" and Data::Dumper

    As you go you get to explain more sytntax as needed and hopefully pique their interest. You can't teach them perl in a day but you can certainly whet their appetites and with the one liners at least give them a couple of useful tools.

    I would skip GOLF and OBFU as they may be fun but don't actually explain why perl is useful.



Re: Requesting suggestions for one day Perl course
by jeffa (Bishop) on Feb 29, 2004 at 21:25 UTC

      Fantastic. Thanks, I will use that (or as much as I can fit in) for my presentation.

      Alex / talexb / Toronto

      Life is short: get busy!

Re: Requesting suggestions for one day Perl course
by ysth (Canon) on Feb 29, 2004 at 20:52 UTC
    Try to cover most of what's on Juerd's perlcheat. If you have extra time, do complex data structures, creating modules, a quick guide to using CPAN.
Re: Requesting suggestions for one day Perl course
by davido (Cardinal) on Mar 01, 2004 at 03:57 UTC
    I liked merlyn's suggestion of teaching from the Llama book. But I had a thought on how you might condense.

    You mentioned that your target audience already have experience with C++. Take the philosophy of leading a horse (or budding Camels) to water, rather than trying to force him to drink. Rather than attempting to teach Perl in a day, teach those parts of Perl that are easy to see as advantageous strengths over, say, C++. If they're thirsty, they'll start with that kind of an introduction and run with it.

    For example, while teaching out of Llama, specifically go over topics such as hashes, lists/arrays, regexps, go heavy on DWIM'ery, file operations, including specifying alternate input record separators, show a trick or two with split, a trick or two with map. Dynamically create code and eval it. Delve a little into references and data-structures. Use that to lead into doing a Schwartzian Transform with short-circuit fallthrough to demonstrate how to sort on multiple criteria... those are just a few thoughts.

    I guess what I'm saying is that you probably can't teach Perl in a day, but you can teach why this group should invest the personal time required to learn it. Stress quick development time, rich syntax, extreme flexibility, etc. Even stress extensibility; the fact that Perl can incorporate C/C++ in its code, and the fact that C/C++ code can embed Perl. And by all means, show off CPAN. You have a good opportunity, in that you're talking to already reasonably coherent programmers. You will be most successful in turning a few of them into Perl programmers if you devote your time to showing what is in store for those who grab the torch and run with it.


•Re: Requesting suggestions for one day Perl course
by merlyn (Sage) on Feb 29, 2004 at 21:19 UTC
    You can teach the llama in a day if you hurry. But that's a bit tough. I can do it, because I know what I can leave out if I'm running behind (things that aren't required to understand later things).

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      You can teach the llama in a day if you hurry.
      Teach it? or just Present it? I have a hard time swallowing the former, and question the usefulness of the latter :)
        The llama presented at normal teaching pace is about 16 hours of lecture. This includes going over the exercises, and some standard joke material {grin}. This also includes any question answering time.

        If we are careful to omit any "slight diversions", then it brings it down to about 12 hours of real lecture. Compressing the presentation slightly can bring that down to 10 hours. Omitting 2 hours of any of the material (usually the stuff at the end) brings it down to 8 hours.

        Why is that so hard to believe?

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

Things you cannot leave out of a one-day Perl course for C++ programmers
by jonadab (Parson) on Mar 01, 2004 at 15:29 UTC

    Given that these are C++ programmers, there are a lot of things you don't have to spend much time on. You can show them one while loop and they'll instantly know how to write while loops. You can show them one if/elsif/else series and they'll understand how that works immediately too. Even suffix conditionals like dosomething unless condition will probably not be hard for them to pick up. (They may not immediately start writing that way, but they'll be able to read code that does that and follow it okay.)

    You'll want to reserve a little more time for things that are starkly different in Perl from C++. You want to spend at least an hour on context, for example. You want to show them Perl builtins that do different things in scalar versus list context, and show them different ways to create different kinds of context (scalar versus list assignment, operators that expect a scalar (such as + and .), list operators (such as print), and so on). After you think they understand all of that, you also want to show them how to make their own subroutines behave differently according to context. If you have time, you'll also want to explain the advantages of this, which won't be immediately apparent to some of them probably.

    If you have time, it would be nice to spend an hour or so on pattern matching.

    You also dursn't fail to explain that Perl doesn't have statements, only expressions, and that *ALL* functions in Perl, if followed by a left parenthesis, take their argument list inside the parentheses and fit into the larger expression. You specifically want to say that the print operator is not an exception to this. Show them how turning on warnings will give them "useless use of foo in void context" messages when they forget about this.

    Also, if you have time, talk about the difference between and and or versus && and ||. The former are useful for linking whole expressions together, but the latter are more useful for linking simple conditions together within a larger expression. When in doubt, parenthesize everything.

    Bonus points if you have time to show them CPAN and several useful modules. Some examples of modules you might show them include WWW::Mechanize, HTML::Tree, Data::Dumper, Archive::Zip, Net::Server, and DateTime, but ideally you should pick modules that would be immediately useful for whatever it is that they do daily.

    ;$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$;[-1]->();print
Re: Requesting suggestions for one day Perl course
by zentara (Archbishop) on Mar 01, 2004 at 15:21 UTC
    Well no one mentioned it yet, so I would suggest touching on CGI, since that will probably interest them from a practical standpoint. Show the params stuff, show them how to setup a form, and do emails from CGI, introduce them to Taint, doing file uploads, etc. That stuff is hard from c++, so they will probably appreciate it.

    I'm not really a human, but I play one on earth. flash japh
Re: Requesting suggestions for one day Perl course
by dragonchild (Archbishop) on Mar 01, 2004 at 16:01 UTC
    Find out what they do in their everyday life and show them how Perl makes their life easy. Remember, these are first and second year students.
    • First thing is syntax. Take the first 2-4 chapters in the Llama and skim over them. (90 min)
    • Show them sorting (20 min) and very simple regexes with capturing (40 min).
    • Show them how push, pop, shift, and unshift make stacks and queues painless (15 min).
    • Spend some time on CGI, showing them how it makes their personal life easy. (30 min)
    • Show them XML::Parser, leading into a light discussion of callbacks. (45 min)

    That's four hours. After that, let them lead the discussion - ask them what they think Perl can do for them.

    We are the carpenters and bricklayers of the Information Age.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      These students have been using C++ and .NET -- I plan to ask the instructor what assignments they've been doing recently, and see if I can take one or two of the tougher ones and doing it in a single line of Perl. I'm hoping for the 'dropped jaw' look. :)

      I'm also going to talk about meta-subjects, such as this web site and the other Perl web sites that are available, as well as talk about the Perl community and YAPC::NA.

      Alex / talexb / Toronto

      Life is short: get busy!

        Maybe then it is a good idea to not pull them out of an environement they are used to but using .NET Perl. It is fully integrateable into Visual Studio.
Re: Requesting suggestions for one day Perl course
by flyingmoose (Priest) on Mar 01, 2004 at 15:12 UTC
    If they know C++, they can probably think for themselves and learn another language on their own. 1-day isn't enough time for spoonfeeding.

    Given they'll be able to pick up the syntax (hopefully they will). I'd show off features and let them learn some on their own. Hashes since they won't be used to them, auto-vivification, all the goodies on CPAN for really obscure stuff that would be incredibly hard in C, the cleanliness of Tk (if they know Java for example, they'll probably hate Swing), functional programming to attempt to blow their minds, etc. They'll be coming back for more if you do it right...

    Also, I think you need to give at least one example of something that is incredibly hard to do in most languages, done in one line of Perl code. Open with it. Something like "who is winning the most democratic primaries by scraping CNN" or stock prices or something like that.

      I won't be spoon-feeding these students -- I hope to be teaching a university level course in Perl, the Perl Community, and by inference, talking about the Open Source community. To get into this program they had to have adequate C, so I'm going to blaze over for and while loops so we can get on to the cool stuff.

      I haven't used Tk and don't want to have to learn stuff for this seminar -- I'll stick with what I know.

      Scraping CNN is a neat idea .. I may even see if I can grab an RSS feed from somewhere and show them how it's done in just a few lines of Perl.

      Alex / talexb / Toronto

      Life is short: get busy!

        Also, it may be obvious, but don't forget to plug PerlMonks as a great resource to go to once you have invested time to learn the language a bit. It has certaintly contributed to my love for the language. I think that's a huge advantage as this is a heavily-trafficked forum. Let them know the author of the llama and many other cool people post here and want to encourage learning and breaking the sound barrier (but this is not to say they shouldn't learn on their own too).

        Maybe run Erudil's Camel Code or Spiraling Quine or Mandelbrot flythrough just for kicks. Again, for the drool factor.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://332692]
Approved by kutsu
Front-paged by kutsu
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2021-11-30 07:22 GMT
Find Nodes?
    Voting Booth?

    No recent polls found