Re: [QUIZ] Perl 'Easy' Quiz #2005-2

Ben Thul <[email protected]> Sat, 5 Feb 2005 12:20:37 -0600
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
Here's my entry into the mix:

sub remove_trailing_dot {
    my ($input) = @_;
    my $idx = index( $input, '.' );
    while ( index( $input, '.', $idx + 1 ) != -1 ) {
        substr( $input, $idx, 1 ) = '';
        $idx = index( $input, '.' );
    }
    return $input;
}

On Wed, 2 Feb 2005 19:54:19 +0200, Shlomi Fish <shlomif-ik1l9ssToec+JF/[email protected]> wrote:
> IMPORTANT: Please do not post solutions, hints, or other spoilers
>         until at least 60 hours after the date of this message.
>         Thanks.
> 
> I've been on FreeNode's #perl channel one day when someone asked how to remove
> all periods from a string except the last one. So for example
> "this.is.a.file.txt" will become "thisisafile.txt".
> 
> Your mission is to write as many different solutions as possible to this
> problem. You should write functions which will accept a single scalar
> argument containing the string, and return a single scalar containing the
> modified string.
> 
> So for example if the function is called "myfunc", the following code:
> 
> <<<
> print myfunc("this.is.a.file.txt");
> >>>
> 
> Will print:
> 
> thisisafile.txt
> 
> Regards,
> 
>         Shlomi Fish
> 
> ---------------------------------------------------------------------
> Shlomi Fish      shlomif-ik1l9ssToec+JF/[email protected]
> Homepage:        http://www.shlomifish.org/
> 
> Knuth is not God! It took him two days to build the Roman Empire.
> 


-- 
Ben