I want to perform a function on every 'word' found in a string.
Basically pass each word through a function which randomly muddles up the middle letters of a word.
I have found 69688 that looks like it will do what I want.. however I dont get the same result as the example suggests:
And yes, I am simply reversing the middle letters not randomly jumbling them.. again I am trying to find a nice clean way of doing this.use strict; my $test = "This is a sample string of text"; my $tost = $test; $test =~ s/(\w)(\w+)(\w)/$1&garble($2)$3/g; print "ONE: $test\n"; print 'TWO: '.&garble($tost); sub garble { # garbles the middle of a word leaving the first and last characters + alone eg hello -> hlelo my $ret = ''; my @txt = split(/\s/,$_[0]); foreach my $word (@txt){ if($word =~ m/(\w)(\w+)(\w)/){ my $start = $1; my $mid = reverse $2 ; my $end = $3; $ret .= $start.$mid.$end.' '; }else{ $ret .= $word.' '; } } return $ret; } # ONE: T?{&garble(hi)}s is a s?{&garble(ampl)}e s?{&garble(trin)}g of +t?{&garble(ex)}t # TWO: Tihs is a slpmae snirtg of txet
Any thoughts?
___ /\__\ "What is the world coming to?" \/__/ www.wolispace.com
In reply to Executing a function within a regex by wolis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |