Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

The Name Game

by Kozz (Friar)
on Jul 19, 2000 at 22:36 UTC ( #23267=sourcecode: print w/ replies, xml ) Need Help??

Category: Fun Stuff
Author/Contact Info Kris Koskelin -
Description: Just a small bit of code to "do the name game" on any name given. I tried to clean up my code quite a bit to appease the monks before posting it, but I'm sure someone's got some ideas on how to improve it. :-)

print "Content-type: text/html\n\n";

  my($myform, $game, $left);
  $$myform{'name'}=~s/(\w)(\w+)/\u$1\L$2/;# capitalize first letter, l
+c the rest
  my @letters=split(//, $$myform{'name'});
   last if scalar(@letters)==0;
   shift @letters;
  $game="!name! !name! Bo-B!left!\nBanana Fanna Fo-F!left!\nMe My Mo-M
  $$myform{'left'}=join("", @letters);

print <<END;
<font face="Comic Sans MS, Verdana, Arial" size=4 color="#FF4444">

 print <<END;

sub showform{
 print <<END;
<title>The Name Game</title>
<form method="POST" action="namegame.cgi">
<input type="text" name="name" size=25>
<input type="submit" value="Name-Game it!">


sub translate_form{
  my($myform, $pair, %myform);
  if ($ENV{'REQUEST_METHOD'} eq "GET"){ 
     $myform = $ENV{'QUERY_STRING'};
     read(STDIN, $myform, $ENV{'CONTENT_LENGTH'});
  foreach $pair (split (/&/, $myform)) {
     $pair=~s/\+/ /g;
     my($name, $value) = split(/=/,$pair);  
     foreach($name, $value){
       s/%(..)/pack ("C", hex ($1))/eg; 
       s/^\s*//sg; # remove leading spaces
       s/\s*$//sg; # remove trailing spaces
     $myform{$name} .= "\0" if (defined($myform{$name})); 
     $myform{$name} .= $value;
  return \%myform;

Comment on The Name Game
Download Code
Replies are listed 'Best First'.
RE: The Name Game
by turnstep (Parson) on Jul 19, 2000 at 23:28 UTC

    Well, you did ask (sort of), so:

    $myform->{'name'}=~s/(\w)(\w+)/\u$1\L$2/; ## You can use perl's builtin functions to do the job: $myform->{'name'}=ucfirst(lc($myform->{'name'});

    You could also replace:

    my @letters=split(//, $myform->{'name'}); while($letters[0]!~/^[aeiouy]/i){ last if scalar(@letters)==0; shift @letters; } $myform->{'left'}=join("", @letters); ## with: ($myform->{'left'}=$myform->{'name'}) =~ s/$[^aeiouy]+//;
Re: The Name Game
by thabenksta (Pilgrim) on May 02, 2001 at 00:57 UTC

    Very nice, this will keep me entertained for hours.

    my $name = 'Ben Kittrell'; $name=~s/^(.+)\s(.).+$/\L$1$2/g; my $nick = 'tha' . $name . 'sta';

Back to Code Catacombs

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2015-10-10 01:09 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (254 votes), past polls