Categories
Misc.

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:

Categories
Misc.

Searching Source Code

Google announced two new services, Google Code Search and Google Blog Search Pinging.

In this post, I’ll discuss Google Code Search. Google code Search is meant to be able to search through publicly available source code based on regular expressions, strings, license type, and a few other criteria. I haven’t done any exhaustive tests on Google Code Search yet but it’s nice to see Google expanding beyond straight search to more refined searches like the type needed for trolling through source code or finding the most relevant blogs.

The user interface is the familiar Google search interface and the results currently don’t appear to be displaying ads.

If you’re in need of a search engine for source code, don’t forget to check out Krugle. I prefer the interface of Krugle a bit more as it’s easy to search for something within source code, and then hit one of the other tabs and show relevant results from blogs or other web pages and from projects as well. This is something for Google to catch up on.

Here are some screenshots of both code searching services.
Google Code Search Home

Google Code Search Home

Google Code Search Results

Google Code Search Results

Krugle Search Results

Krugle Code Search Results

Read more about Google Code Search: Official Google Blog: More developer love with Google Code Search

technorati tags:, , ,

Blogged with Flock

Related Posts:

Categories
Misc.

Google International Code Jam Coming to NYC

Google has announced that they will be holding their prestigious International Code Jam in New York City. The 100 best programmers will be flown from around the world to the Big Apple, all expenses paid, to compete for the $10,000 first place prize. Read more on Official Google Blog: Code your way to Gotham and if you’re upto the task, register here.

technorati tags:, , , ,

Blogged with Flock

Related Posts:

Categories
Bootcamp

Javascript Bootcamp

Via Ajaxian, I cam across this Javascript tutorial presentation given at OSCON. For anyone working with Web technology, this is a great resource on Javascript. Take a look and download source code, presentation given at OSCON 2006, etc.

Even though AJAX wouldn’t ever have become so popular if the Javascript world hadn’t suddenly exploded with mature development and testing tools, there’s little information on how to be a really good Javascript programmer.

Javascript Boot Camp Tutorial

technorati tags:, , , , ,

Blogged with Flock

Related Posts:

  • No Related Posts