in reply to Twiddle

There's also a simple regex solution to that ;-)

#!/usr/bin/perl -w use strict; print 'What string would you like to twiddle? '; chomp(my $twiddle = <STDIN>); $twiddle =~ /^(.+?)(?{print $1,"\n";})$/; # up chop($twiddle); $twiddle =~ /^(.+)(?{print $1,"\n";})^/; # down

-- Hofmator

Replies are listed 'Best First'.
Re: Re: Twiddle
by petral (Curate) on Jul 12, 2001 at 21:27 UTC
    Amazing! Especially the  ^/ to force backtrack on failure. And of course, the obligatory 1-liner:
    > perl -le'$_=pop;/^(.+?)(?{print$1})$/;/^(.+).(?{print$1})^/' hello h he hel hell hello hell hel he h >
      p

      Thanks all, I'm just learning perl, and that was my first attempt at a program in this language. I'll keep your suggestions in mind. Siggy