
fashimpaur
User
/ Moderator
Feb 12, 2002, 5:46 AM
Post #1 of 9
(80374 views)
|
Phone Number Input Fix Golf
|
Can't Post
|
|
The problem: Let's say you have an HTML form out on the Web for information gathering for a business that will contact the customers requesting information by the phone number they enter in a single text input box. The box does not restrict character input in any way. We will assume for argument sake that the person filling out the form will enter the phone number keeping all the area code digits together, all the prefix digits together and all the extension digits together. We will also assume it is a standard US 10-digit phone number. The person filling out the form can use any number of characters or spaces between the groupings.
The challenge: In the fewest number of characters of perl code, print any phone number entered to STDOUT always in the format ($_ can equal phone number from form): sprintf("(%.3s) %.3s-%.4s", $area, $prefix, $extension); If all three parts are not present, the script must die (no message necessary for challenge). To score, count all keystrokes in your code. 1 point for each keystroke. Fewest points wins! My best score is 41. [spoiler]/(\d{3}).*(\d{3}).*(\d{4})/?print"($1) $2-$3":die;[/spoiler] Good Luck. P.S. Jasmine - The spoiler mnemonic is not working correctly. The text showed up until I turned it white. Dennis $a="c323745335d3221214b364d545". "a362532582521254c3640504c3729". "2f493759214b3635554c3040606a0", print unpack"u*",pack "h*",$a,"\n\n";
|