New Quiz: "What does this code do?" (3-Jan-2006)

Shlomi Fish <shlomif-ik1l9ssToec+JF/[email protected]> Tue, 3 Jan 2006 14:36:39 +0200
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
In the Israeli Perl Mongers mailing list we used to hold quizzes in which I 
would paste Perl code snippets and people needed to understand what they did, 
and possibly guess for what purpose they served.

I am going to import this tradition here, and have a "What does this code do?" 
quiz. You are given the following Perl program, and have to understand what 
it does, and why was it written.

Here goes:

<<<<
#!/usr/bin/perl

use strict;
use warnings;

my $string = shift;
foreach (@ARGV)
{
    if (/^([^=]+)=(.*)$/)
    {
        my ($v, $s) = ($1,$2);
        if (substr($string, 0, length($s)) eq $s)
        {
            if ((length($string) > length($s)) ?
                (substr($string,length($s), 1) eq "/") :
                1
               )
            {
                print $v . substr($string, length($s));
                exit(0);
            }
        }
    }
    else
    {
        die "Bad";
    }
}
print $string;
>>>>

Before the 60 hours quota is over, you can send your solutions to me in person 
(shlomif-ik1l9ssToec+JF/[email protected]).

Regards,

	Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish      shlomif-ik1l9ssToec+JF/[email protected]
Homepage:        http://www.shlomifish.org/

95% of the programmers consider 95% of the code they did not write, in the
bottom 5%.