Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Twiddle

by Hofmator (Curate)
on Jul 12, 2001 at 15:03 UTC ( #95972=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://95972]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2019-06-24 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (99 votes). Check out past polls.

    Notices?