Enter a number: <input type="text" name="number" size=”2”><p>
<input type="submit" value="Generate">
</form>
</body> </html>
Save the page as veryrandom.html in the PERL PRACTICE folder on your computer, then upload it to the home directory in your Web site.
Write a script that:
- Executes a subroutine called getFormData to pull information from the form input box in veryrandom.html.
- Prints the paragraph
Here’s a really random number:
to the browser window.
- Executes a subroutine called randomize. Add a subroutine called randomize to the script that:
- Creates a random number, then assigns it to a variable called $random integer:
$random_integer = int(rand(10))
- Requests the number put in the form field, then assigns it to a variable called $number_input:
$number_input = $request{'number'}
- Adds the variables, assigning the sum to the variable $randomized:
$randomized = $random_integer + $number_input
- Prints the randomized number to the browser window.
Copy the subroutine getFormData from dreamcar.pl, and paste it into the script.
TIP: There are now two subroutines in this script: getFormData and randomize.
Save the script as veryrandom.pl in the PERL PRACTICE folder on your computer.
Upload it into the practice directory in your Web site, then change its permissions so that anyone can execute it. View veryrandom.html in the browser, enter a number, then click the button.
0201200 comments, (762 reads) All Articles by, GentleGiant