Perl for Beginners at BarCamp Delhi

Yesterday at BarCamp Delhi Prateek and Pratul decided to hold a hack-a-thon. The idea being, that in 2 to 3 hours, the group of programmers assembled would hack together some application. Some of the ideas thrown around were:

  • A Firefox Plugin
  • A Firefox Greasemonkey Extension
  • A manufacturing, logistical support web app

Pratul and Prateek probably have a more complete list than I do. The hack-a-thon broke apart into a few groups, each doing something different. No applications were built but a few Windows programmers were interested enough that I spent about 20 minutes showing them a few “Hello World” Perl scripts.

I’ve attached the Perl scripts for the folks who asked for them and any others that might be interested. Also, if anyone is interested in learning Perl, I highly recommend this book. It says 21 days to learn Perl but most of you will probably pick it up in less than a week.

Unfortunately, the extensions of the files are being changed to .txt so please take off the .txt once you download the files. I’m also putting the scripts inline.

hello.pl: A simple Hello World script


#! /usr/bin/perl

use warnings;
use strict;

my $name = "Pankaj";
print "Hello $name.n";


hello2.pl: A “Hello World” script that uses a very simple Perl module (below)


#! /usr/bin/perl

use warnings;
use strict;

use lib("../lib");
use Hello;

my $name = "Pankaj";
Hello::hello($name);


Please put the Hello.pm in a relative path to where you put hello2.pl as described in “use lib” line above in hello2.pl.

Hello.pm Our very simplistic Perl module


package Hello;

sub new {
}

sub hello{
my $name = $_[0];
print "hello " . $name;
} #
# ------------------------------------------------------------
1;


And our final example that one of the campers asked for was a Perl script that would take input from the command line interactively.

hello3.pl: Our final “Hello World” script that interactively asks for names on the command line.


#! /usr/bin/perl

use warnings;
use strict;
use Getopt::Long;
use Term::ReadLine;

my $foo;
my @bar;

GetOptions("foo=i" => $foo);

my $count = 0;
my $term = Term::ReadLine->new();

while ($count readline("What is your name? ");
$bar[$count] = $line;
$count++;
}

foreach my $f (@bar) {

print "bar is $fn";
}


We didn’t get to it but would one of the campers like to take one of these scripts and turn them into a CGI script or a mod_perl application? Please post your changes in a comment to this post.
Cheers

Related Posts:

The Financial Crisis and India

BarCamp Delhi has been going on this weekend. I don’t think anyone took any video of the presentation but I turned into a bit of a pig and took up three speaking slots.

Sorry to Netra, Sukhdeep and every one else for taking up their slots!

The presentation is available as a download below as well as on Slideshare.

So far, there are posts on BarCampDelhi5 coverage on Webyantra and the BarCampDelhi Blog.

Related Posts:

BarCamp Delhi @ IIT Delhi on October 11th and 12th

BarCamp Delhi is set for October 11th and 12th. IIT Delhi is playing host to this two day event. The location will be the Bharti building on the IIT campus. There are two rooms on the first floor, two rooms on the second floor and one room on the third floor available for campers. There will also be plenty of space available inside and outside for ad-hoc meets and networking.

Remember, everyone attending BarCamp must should participate in some capacity, whether it is presenting, taking pictures or videos, live blogging, or just volunteering for various tasks in organizing a BarCamp. Please take a look at the BCD5 Sessions page and add yourself to the list of presenters.

If you’re one of those people who get inspired at a moment’s notice and aren’t sure what you might be presenting on right now, you can still add your name to the list of Campers for BarCamp Delhi.

Looking forward to meeting you at BarCamp Delhi, the 5th edition on October 11th and 12th.

Update 2008-09-21: Some of the volunteers for BarCamp Delhi had our first face to face meeting today at the Teknatus office. We discussed quite a few items, settled on some open issues, and handed out various tasks. In the immortal words of Col. John “Hannibal” Smith, “I love it when a plan comes together.”

Related Posts:

BarCamp Delhi Marketing/PR

BarCamp Delhi is scheduled for October 11th and 12th 2008 at IIT Delhi. We’re currently working on reaching out to bloggers to help spread the word. We’re looking to attract thinkers in various fields, in India and outside, to attend the even and share their thoughts with the rest of us.

If you know of any bloggers that we should contact directly, please enter the information in the form below.

Cheers

Related Posts: