Cool/useful short examples of Perl?

Leo Lapworth leo at cuckoo.org
Mon May 30 11:40:57 BST 2011


Hi,

I'm working on http://learn.perl.org/ and I'd like to have a few rotating
example of what can be done with Perl on the home page.

The first two I've thought of are below, does anyone have others?

They don't have to use CPAN modules, one liners are fine as long as it
is simple to see what they do. I'll have a 'more' link which goes on to
show full example with line by line explanations.

Module preference is anything from http://search.cpan.org/dist/Task-Kensho/

E.g.:

This is probably max sort of size...

  # Send an email
  use Email::Sender::Simple qw(sendmail);
  use Email::Simple;
  use Email::Simple::Creator;

  my $email = Email::Simple->create(
    header => [
      To      => '"Xavier Q. Ample" <x.ample at example.com>',
      From    => '"Bob Fishman" <orz at example.mil>',
      Subject => "don't forget to *enjoy the sauce*",
    ],
    body => "This message is short, but at least it's cheap.\n",
  );

  sendmail($email);

or

  # Serve static files from document root with a directory index
  # app.psgi
  use Plack::App::Directory;
  my $app = Plack::App::Directory->new({ root => "/path/to/htdocs" })->to_app;

  > plackup
  > Accepting connections at http://0:5000/

Thanks in advance!

Leo


More information about the london.pm mailing list