Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Requesting suggestions for one day Perl course by tachyon
in thread Requesting suggestions for one day Perl course by talexb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-26 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found