in reply to Rotating a string

I'm not sure what all those reverses are doing there. What's wrong with just this?
sub rot { my ($str, $rot) = @_; substr($str,$rot).substr($str, 0, $rot); }

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: Rotating a string
by ariels (Curate) on Dec 04, 2000 at 11:14 UTC
    It's "in-place-able" (though of course the Perl compiler doesn't know this). If ireverse were an in-place reverse, I could write
    ireverse substr($str,0,$rot); ireverse substr($str,$rot); ireverse($str);