Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
laziness, impatience, and hubris
 
PerlMonks  

Re: Executing a function within a regex

by zude (Scribe)
on May 10, 2004 at 03:20 UTC ( #351944=note: print w/ replies, xml ) Need Help??


in reply to Executing a function within a regex

To scramble every word in a string leaving first and last characters intact:

$string = "Hello there this is a scrambled mess"; sub scramble($) { my @a; splice @a,rand (@a+1),0,$_ for split '',(shift); join '',@a; } ($scrambled = $string) =~ s/(?:(?<=\A\w)|(?<=\W\w))\w+?(?:(?=\w\Z)|(?= +\w\W))/scramble $&/eg; print "$scrambled\n";
Hlelo trehe tihs is a smlbceard mess


Comment on Re: Executing a function within a regex
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2013-05-23 05:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (473 votes), past polls