Pious Monks,
I've heard about funny attribute people's perception.
Look at this:
I tnhik you know what I am wintirg to you. But I must rbemeer to keep fsirt and last lteerts on the plcae and do not tucoh sorht wdors.
It's nice, istn't?
So, I try to write function to do it:
sub perception() {
my @result;
my @words = split / /, shift @_;
foreach my $word (@words) {
if ( length $word < 5 ) {
push @result, $word;
next;
}
my @toRandomize = split //, $word;
my $letters = ( ( scalar @toRandomize ) - 1 );
$letters-- if $word =~ /\W$/;
for ( my $i = 1 ; $i < $letters ; $i++ ) {
my $rnd = ( 1 + ( int rand( $letters - 2 ) ) );
my $temp = $toRandomize[$i];
$toRandomize[$i] = $toRandomize[$rnd];
$toRandomize[$rnd] = $temp;
}
push @result, join( '', @toRandomize );
}
return join ' ', @result;
}
What are you think about this?
How can I do it better?
And, how to work with words like "your's", "you're" etc.? - " ' " should stay on the place.
$letters-- if $word =~ /\W$/;
if ( $word =~ /\W+/) {
$letters = (index $word, $&)-1;
}
Stay in peace and wisdom, monks.
Uksza
P.S.
Is my code styl good? Not to much "talkative"?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|