Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Typoglycemia Fun

by tcf03 (Deacon)
on May 21, 2005 at 02:25 UTC ( #459181=note: print w/replies, xml ) Need Help??


in reply to Typoglycemia Fun

or for the web-venturous
#!/usr/bin/perl -T use strict; use warnings; #use diagnostics; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); # Clean up our UNIX environment # for more infor read perldoc perlsec $ENV{'PATH'} = '/awiopt/radio:/tmp'; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Flush the output buffer $|++; my @text; # shuffle function from List::Util sub shuffle (@) { my @a=\(@_); my $n; my $i=@_; map { $n = rand($i--); (${$a[$n]}, $a[$n] = $a[$i])[0]; } @_; } print header; print start_html(-title=>"Fun with Typoglycemia", -BGCOLOR=>"#cccc99" ), "\n"; print "<tt><center>\n"; print h3("Fun", "With", "Typoglycemia"),"\n"; print "</center>\n"; print hr,"\n"; print "\n\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" wid +th=\"70%\" align=\"center\">\n\n"; print "<tr align=\"center\" bgcolor=\"#999966\">\n <th>Typoglycemic Text</th>\n </tr>\n"; print "<td>\n"; if ( defined (param('TEXT')) ) { # $/=undef; @text=param('TEXT'); for (@text) { my $line = $_; my $line_copy = $line; while ($line =~ m/(\w+)/g) { next if length($1) < 4; my $start_offset = pos($line) - length($1) +1; my $word_middle_length = length($1) - 2; # force two character lead-in and lead-out if ($word_middle_length > 4) { $word_middle_length -= 2; $start_offset++; } my $word_middle = substr($line, $start_offset, $word_middle_le +ngth); my $shuffled_word_middle = join('', shuffle( split(//, $word_m +iddle) ) ); substr($line_copy, $start_offset, $word_middle_length) = $shuf +fled_word_middle; } print "$line_copy\n"; } } print "</td>\n"; print "</table>\n"; print br,br; print "\n\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" wid +th=\"70%\" align=\"center\">\n\n"; print "<tr align=\"center\" bgcolor=\"#999966\">\n <th>Enter your text</th>\n </tr>\n"; print "</table>\n"; print br,br; print start_form; print "<center>\n"; print textarea('TEXT',"", 15, 80), "\n",br; print submit; print end_form; print "</center>\n",br; print "\n\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" hei +ght=\"20\" width=\"70%\" align=\"center\">\n\n"; print "<tr align=\"center\" bgcolor=\"#999966\">\n <td> </td>\n </tr>\n"; print "</table>\n",br; print end_html;

I couldn't resist...
Ted
--
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
  --Ralph Waldo Emerson

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2023-02-05 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (31 votes). Check out past polls.

    Notices?