Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Requesting suggestions for one day Perl course

by tachyon (Chancellor)
on Feb 29, 2004 at 21:12 UTC ( [id://332702]=note: print w/replies, xml ) Need Help??


in reply to Requesting suggestions for one day Perl course

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.

cheers

tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://332702]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-19 05:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found