Home arrow Perl Programming arrow Page 5 - Perl 101 (part 8) - Putting It To The Test

...And The Explanation - Perl

In the concluding article in the Perl 101 series, everythingyou've learnt so far is put to the test when you develop some real-worldCGI applications - a counter, a guest book and a form mailer.

TABLE OF CONTENTS:
  1. Perl 101 (part 8) - Putting It To The Test
  2. Adding Things Up
  3. Visitors Welcome!
  4. The Code...
  5. ...And The Explanation
  6. Going Backwards
  7. Fortune Cookies
  8. You Have Mail!
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 4
October 02, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Let's start from the top. We've first defined a variable, $in, that accepts a value from the form. As explained in our previous example, all the form variables are passed to the script as name-value pairs. However, in this case, we are passing more than one name-value pair, separated from each other with an ampersand.

Therefore, it becomes necessary to split the input string against the & to get the individual name-value pairs. Each name-value pair is stored as an element of an array. When we begin printing the data entered (for verification), it becomes necessary to again split each element of the array into individual "names" and "values" against the = symbol. Splitting things up this way also makes it simple to write the different items to a text file.

Using the "foreach" loop, we split each element of the array, as described above, into a temporary hash variable. We can then extract the name-value pair from the temporary hash and display it to the user.

Since we have to also store the values in a text file, we've created a variable named $entry, formatted it in such a way that it contains all three values entered by the user (separated by a # symbol), and dumped it into a text file. Remember to open the file in "append" mode!

This article copyright Melonfire 2000. All rights reserved.

 
 
>>> More Perl Programming Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PERL PROGRAMMING ARTICLES

- Perl Turns 25
- Lists and Arguments in Perl
- Variables and Arguments in Perl
- Understanding Scope and Packages in Perl
- Arguments and Return Values in Perl
- Invoking Perl Subroutines and Functions
- Subroutines and Functions in Perl
- Perl Basics: Writing and Debugging Programs
- Structure and Statements in Perl
- First Steps in Perl
- Completing Regular Expression Basics
- Modifiers, Boundaries, and Regular Expressio...
- Quantifiers and Other Regular Expression Bas...
- Parsing and Regular Expression Basics
- Hash Functions

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: