views:

1355

answers:

17

I would like to give a presentation for my co-workers that will show off some amazing things that Perl can do, things that would make programmers and non-programmers alike say to themselves, "WHOA you can do that?!" I really want to turn heads, since many are of the mindset that Perl is a dying language, but also be fun and entertaining.

Some ideas I have are demos of the following modules:

Any recommendations or comments?

BTW we are a tech company (run a data center) so the computer literacy of my co-workers is high.

+17  A: 

Years ago, when I was first learning how to program, my girlfriend's cousin showed me a Perl script he'd written which contacted a database containing the positions of all known satellites, and calculated the flyover times for the largest objects, like the space station Mir. The script ran via cron on a server he ran, and it would run periodically and then send him a page about 5 minutes before the given object was visible overhead in the night sky. As we were walking around town, he could get everybody's attention by suddenly pointing up and saying "LOOK!", and everybody ooohed and ahhhed right as the satellite cruised overhead.

I was really impressed by that script at the time, since I had no idea how to write a program nearly that complex. Now that I would have a much better idea, I still think it made a good demo, as it showed something novel that could be done with the language in a relatively short amount of time and with little sweat. So I'd say to pick something novel or interesting, and emphasize Perl's economy of language, and its networking capabilities.

Nik Reiman
Can you ask your friend for that script? I just want to appear that cool too (in the right circles)
Richard
sorry, no can do. ;) This was about 10 years ago, and since than that gf is an ex-gf whom I've long since lost touch with.
Nik Reiman
I have a doubt that a satellite can be seen by a naked eye (I have no doubt that the script can be written).
J.F. Sebastian
^^ http://en.allexperts.com/q/Astronomy-1360/Observing-Satellite-Naked-eyes.htm
Nik Reiman
Thanks for the link. Airplanes are the only type of fast-moving objects visible in the sky in my neighbourhood.
J.F. Sebastian
You can see some satellites with the naked eye, sometimes even in the day time if you know where to look.
brian d foy
You can definitely see large satellites - the International Space Station looks like a huge, glowing star that moves across the sky.
Callum Rogers
+5  A: 

Some combination of screen-scraping, interacting with external programs, and parsing a text file really quick would impress people. The example given by squook would definitely fit the bill.

On the other hand, why not just use it in your day-to-day work, write tremendously useful tools that everyone else uses, and explain to people that you made the tools in Perl? That way you're getting useful things done for work, and people at your workplace surely would appreciate the value of getting work done. :)

James Thompson
+7  A: 

I believe CPAN is pretty impressive in and of itself. The ease of installation of new modules is pretty nice, as is the fact that they are all there.

And then combining modules to do cool things: generating RSS (or Atom) from pretty much any data that passes by, using GraphViz::* to generate pretty pictures (tm).

You could also look at the tutorials of some of the big framework type modules, Catalyst or POE for example, they have some pretty nifty things you can do with little code.

If the local culture is not too uptight, a few of the Acme::* modules (Acme::Bleach for example) are pretty clever and sure to get you some laughs.

Finally, using XML::Twig of course, a one-liner that gives you the current exchange rate between the dollar and the euro:

perl -MXML::Twig -l -e'print XML::Twig->parse( "http://www.x-rates.com")->first_elt(q{a[@href="/d/USD/EUR/graph120.html"]})->text' 

It's pretty easy to adapt it to scrap data from another website.

mirod
Good ideas, thanks, the Acme::Bleach reminded me of Acme::EyeDrops which I like
mcsnolte
http://search.cpan.org/dist/Acme-Bleach
Brad Gilbert
+9  A: 

Show them Frozen Bubble.

Ant P.
+2  A: 

If you wanted to use Image::Magick, you could do a quick script that could turn a regular picture into ASCII art. That would be a fairly quick script to do. Apply the sobel operator and then convert the resulting brightness into ASCII values. I've actually done this in Python: example.

contagious
+4  A: 

One of the coolest things to me is using Perl for code generation. Especially when it comes other languages. I have wrote several small scripts to generate C++ classes, and Java code.

Back when I was a Perl neophyte. I wrote this piece of code, that generated schema files based on our database. About 2 hours later I found out that I didn't need to do this for DBIx::Class. This is not great Perl code (don't down vote me for it. It's just an example), but it accurately generated like 200 schema files for me.

my @db = `mysql -u XXXXX -pXXXXX --skip-column-names -e "show databases;"`;

foreach my $db_name (@db) {
    chomp($db_name);
    my @tables = `mysql -u XXXXX -pXXXXX --skip-column-names -e "use $db_name; show tables;"`;
     $_ =~ s/\n// foreach(@tables);

    unless ( -e "$db_name.pm") {
        open(DBFILE, '>', "$db_name.pm");
        print DBFILE "package mysql::schemes::$db_name;\n";
        print DBFILE "use base qw/DBIx::Class::Schema/;\n\n";
        print DBFILE '__PACKAGE__->load_classes(qw/' . join(' ', @tables) . "/);\n\n";
        print DBFILE "1;";
        close(DBFILE);
    }
    mkdir $db_name unless ( -d $db_name or -e $db_name );
    foreach my $table_name (@tables) {
           my @columns = `mysql -u XXXX -pXXXX --skip-column-names -e "USE $db_name; desc \\\`$table_name\\\`;"`;
           $_ =~ s/\n$// foreach(@columns);

           my (@names, $primary_key);
           foreach (@columns) {
                my ($name, $type, $null, $key, $default) = split(/\t/, $_);
                chomp($default);
                push(@names, $name);
                $primary_key = $name if($key ne '');
            }

            unless ( -e "$db_name/$table_name.pm" ) {
                open(TBFILE, '>', "$db_name/$table_name.pm");
                print TBFILE "package mysql::schemes::" . $db_name . "::" . $table_name . ";\n";
                print TBFILE "use base qw/DBIx::Class/;\n\n";
                print TBFILE "__PACKAGE__->load_components(qw/PK::Auto Core/);\n";
                print TBFILE "__PACKAGE__->table('$table_name');\n";
                print TBFILE "__PACKAGE__->add_columns(qw/" . join(' ', @names) . "/;\n";
                print TBFILE "__PACKAGE__->set_primary_key('$primary_key');\n\n" unless($primary_key eq '');
                print TBFILE "1;";
                close(TBFILE);
            }
    }
}
J.J.
+3  A: 

Demonstrate complex data manipulation with a one liner, like parsing a web server log and for 404 errors, then another oneliner to remove the broken links from a collection of HTML documents...

I taught a Perl workshop to a group of long-time sysadmins one time, and they saw the most value when they saw how they could use real programming tricks like modularization and data structures to improve their shell scripts, in a way that had continuity with what they already knew. In a Windows environment I'd demonstrate manipulating large file structures, permissions and the Registry, because everyone always needs that sort of thing and Perl is way more robust than batch files, etc.

Nathan
+3  A: 

I think being able to write macros to manipulate the Windows Clipboard is pretty impressive. It has all sorts of possibilities, and gives you the power of Perl from just about any Windows app where you can cut/paste text.

runrig
A: 

On the frivolous and entertaining side, Damian Conway's entry into the third obfuscated Perl contest, SELFgol performed 4 tasks

* Its a quine (when executed, prints an exact copy of itself)
* Turns other programs into quines
* Plays Conway's Game of Life
* Animates a marquee banner

And all this in under 1000 characters. Pretty entertaining.

Leonard
+6  A: 

After showing them search.cpan.org (and explaining the concept of CPAN), show them any of the following:

Then blow their minds with a sort/map/grep combo (aka Schwarzian Transform) that does more work in 1 line of code than you could in 50 lines of C#.

Show them threads and forks, then compare that with the same code necessary to accomplish the same work under Java or C#.

If they aren't blown away by the fact that Perl has had for years the same idioms that C# is just now introducing, then I don't know what to say.

JDrago
+1 for making me discover Imager.
Renaud Bompuis
You seem to be bashing C# a lot. Schwartzian Transform in 1 line of C# with LINQ (this is for files): files.Sort((x, y) => GetDate(x).CompareTo(GetDate(y))); Threads you just use System.Threading, which gives similar amounts of code to do the same as perl's threads - or just use constructs like delegates with their BeginInvoke() method or (now in C# 4) the task library and high level controls like Parallel.For() et al to reduce the code need to below that of manual thread handling. I hope Perl has had features these longer than C#, considering Perl is 22 years old and C# only 8.
Callum Rogers
@Callum Rogers: JDrago's point is that C# didn't have these features initially, while Perl had them 15 years ago. The purpose is probably to annoy the Lispers among us.
reinierpost
+1  A: 

First thought: App::Asciio (see a screencast)

Second thought: It's hard to demo things without a small, tight case. Rather than invent them, you might borrow from others to show the elegance of Perl.

One option would be the solutions to the Microsoft Scripting Games. Jan Dubois of ActiveState provided solutions with commentary that you could use/adapt. (Personally, I found that many of my solutions took much less code, so you might want to edit them down and make Perl seem even more elegant.)

Another option could be going through some of Randal Schwartz's columns. There are some gems in there. (E.g. Fingering myself with Twitter)

As for applications, Perl::Critic is pretty awesome. As is ack.

xdg
A: 

If you are at an IT center, you probably have a number of computers around... mini computers, mainframes, PCs, etc.

How about a script that goes out and gets some sort of information about these machines, that your IT people need, and serve it up nice in some HTML format.

A long time ago, I had 15 TCP/IP based servers that did something for various clients. I put together a Perl script that extracted the parameters for each of the servers, and inserted this information into a new Excel spreadsheet, one tab per server. It then put it on a file server somewhere where everyone could examine it. It saved a lot of time for the people who were supporting the servers.

Look around for a situation where you can make their life easier by reducing manual drudgery. I think that is your best bet.

EvilTeach
A: 

Since most programming languages are fairly comparable at the how-quickly-can-you-implement-something level, maybe you could "wow" them with the solidity and worthiness of the Perl platform? Here are some interesting statistics on how well tested the Perl distribution and CPAN modules are. The CPAN is an amazing creation too, with its associated documentation, search, review, annotation and bug tracking websites. CPAN Testers is definitely the icing on the cake: a collection of testers on multiple platforms and Perl versions.

Gaurav
+4  A: 

I always say the same thing, but in order to show people the usefulness of CPAN, I would present them the problem of parsing English text into its component sentences.

A smart audience presented with that problem will probably say "Just split on a full stop". Then edge cases and problems will start to occur to them. Full stops appear in all kinds of other places; sentences end with question marks and exclamations and three trailing full stops... What about full stop or ! or ? followed by space, no but that won't work because it might be followed by EOF, etc. etc.

If you prepare some tricky text with all those edge cases in it, you'll be able to shoot down all their proposed solutions by just pointing to an example. Then you would parse it with Lingua::En::Sentence.

It's not flashy in the sense you might mean, but it shows the power of a module written by people who have gone through all of the problems which are only just now occurring to your audience, and solved them.

AmbroseChapel
Actually, if an ellipsis occurs at the end of a sentence, it's supposed to have four full stops.... Three is for... sentence internal ellipses.
jcdyer
A: 

My favourite Acme modules are Acme::Eyedrops and Acme::Bleach. Good for light relief.

singingfish
+1  A: 

Most of the answers here I don't think are really going to wow anyone, especially a tech crowd. They might be surprised that Perl can do it, but they aren't going to be surprised that you can do the task. However, even if they aren't surprised that you can do it, they might be surprised how fast, or with how little code, you can do it.

If you're looking for things to show them that will wow them, you have to figure out what they think is hard in their jobs and see if Perl could make it really easy. I find that people tend not to care if a language can do something they don't already have an interest in. That being said, impressing anyone with Perl is the same as impressing anyone in any other subject of field: you have to know them and what they will be impressed by. You have to know your audience.

Perl doesn't really have any special features that allow it to do any one thing that some other language can also do. However, Perl combines a lot of features that you usually don't find in the same programming language.

Most of the things that I'm impressed by have almost nothing to do with the language:

  • There's a single codebase that runs on a couple hundred different platforms, despite differences in architecture.

  • Perl's CPAN is still unrivaled among other languages (which is really sad because it's so easy to do the same thing for other languages).

  • The testing culture has really raised the bar in Perl programming, and there's a lot of work that teases out platform dependencies, cross-module issues, and so on without the original developer having to do much.

brian d foy
A: 

This is done in perl for win32 http://www.unix.gr/FLOSSeavesDrop.exe

It is a remote screen auditing aid. Run it on a windows PC, and then you can monitor its main display with just a web browser. Target your browser at the PC's IP at port 42000

Angelos Karageorgiou