Scott Penrose scottp at
Tue Nov 19 15:10:07 CST 2002

# NOTE ON POD - It is cheat pod - easier to read in Email, not proper 


Hello and welcome to our first competition.


The following code is a simple example of some useful code. The idea is
to provide a number of alternatives to the code in the categories 
below. These will then be judged and the best in each category will win
a bag of Jelly Beans complements of :-)


I was writing some code which allowed you to enter a URL where the 
would automatically move backwards until it found the closest match.

In doing so it was decided that we did not want the URLs to be 
mistyped in important places. Therefore we needed a scheme that would
optionally allow bits of the URL to be chopped off.

The simple solution that we came up with was replacing the '/' in the 
with a '|', where on failure to find a page would fall back one step.

Eg: the url "/A/Very/Big|Directory/Reference|Links"

Would return one of (first one to exist wins)

	* "/A/Very/Big/Directory/Reference/Link"

	* "/A/Very/Big/Directory/Reference"

	* "/A/Very/Big"

=head1 THE PERL

There are just SOOO many ways to do this. The following code is a very
simple, spread out example code.

However, I am always looking for the better way to do it. Combining list
operations (like grep, sort) are methods of reducing the need for 
variables etc, but tend to drag my mind into the lands of lisp :-) but
they can be much more explanatory if formatted correctly.


To demonstrate the better layout, performance, size and flexibility of
good perl code for the good of all I am going to offer a bag of Jelly 
to the winner of each of the following categories. Winners of each
will be chosen by the current Perl Mongers Admin Committee (admin 
will be able to enter code, but only as examples for the web site and
not for the competition).

In all of the following (except EXISTING MODULES), no perl modules
should be used, only core language. Only one entry per category per 

Entries must be received by 6pm Monday the 25th of November.

The command line inputs and outputs should be similar to the example, 
not necessarily the same. The 'sub test' emulating the module will not
be judged, but should not contain any of the logic.


A version of the code that performs the fastest, no matter how ugly or
how long.


A version of the code with the shortest source, not counting white space
or comments.


The best overall version to read and maintain, the sort of code you
would like to read and maintain if someone else wrote it.


Demonstrate your CPANability and show what modules could be used to
help this problem.


Hmmm.... says it all :-)

=head2 PERL 6

A perl6 version. Judged on a balance of easy to read, length and
use of Perl 6 features.

=head1 RESULTS

Results will be judged over the following week and should be completed
by Sunday 30th of November.

The winners and interesting entries will then be formatted as examples
on our web site for others to benefit from.


# ----------------------------------------------------------------------
# Test String =
my $test = $ARGV[1] || "A/Very/Big|Directory/Reference|Links";

# ----------------------------------------------------------------------
# Test object create in order of
#	A/Very/Big/Directory/Reference/Link
#	A/Very/Big/Directory/Reference
#	A/Very/Big
# All other alternatives are not valid (eg: /A/Very/Big/Directory)

my $ret = undef;
my ($key, @try) = split(/\|/, $test);
while (!defined($ret)) {
	print STDERR "Try = " . join('/', $key, @try) . "\n";
	$ret = test(
		join('/', $key, @try)
} continue {
	last unless (pop @try);

print "Return Value = $ret\n";
exit 0;

# ----------------------------------------------------------------------
# The dummy test object - pretend to return a blessed object or undef.
sub test {
	return ($_[0] eq ($ARGV[0] || 'A/Very/Big')) ? 1 : undef;


Scott Penrose
Anthropomorphic Personification Expert
scott at

Dismaimer: While every attempt has been made to make sure that this 
email only contains zeros and ones, there has been no effort made to 
guarantee the quantity or the order.

More information about the Melbourne-pm mailing list