[Israel.pm] What does this code do? (No. 2)
Shlomi Fish
shlomif at iglu.org.il
Mon Jun 21 06:49:39 PDT 2004
Hi all!
Well, here's another code for you to understand what it does. It was
originally written in C, and later converted to Perl. You should understand
what it does without running it. If possible, write a more Perlish version.
(This time there isn't a recursion)
Please don't post spoilers until a week from now, but you can send answers to
me in private. (just make sure you override the Reply-To: header).
Regards,
Shlomi Fish
<<<
package Foo;
use strict;
sub foo
{
my $in1 = shift;
my @s = split(//, $in1);
my @ret;
my $i = 0;
while(($i < @s) && ($s[$i] ne ':'))
{
push @ret, $s[$i++];
}
if ($s[$i] eq ':')
{
push @ret, $s[$i++];
while ($s[$i] eq '/')
{
push @ret, $s[$i++];
}
while ($i < @s)
{
push @ret, $s[$i];
if (($s[$i] eq '/') && ($i+1 < @s) && ($s[$i+1] eq '/'))
{
$i++;
while (($i < @s) && ($s[$i] eq '/'))
{
$i++;
}
}
else
{
$i++;
}
}
}
return join("", @ret);
}
1;
>>>
--
---------------------------------------------------------------------
Shlomi Fish shlomif at iglu.org.il
Homepage: http://shlomif.il.eu.org/
Quidquid latine dictum sit, altum viditur.
[Whatever is said in Latin sounds profound.]
More information about the Perl
mailing list