Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

SQL etc

Posted Aug 30, 1999

Using a flat-file database in Perl - Page 2

By Jason Shindler

Some quick Perl basics

Perl is a multipurpose language. It has lots of other uses besides what we are doing. So, if you are looking to learn Perl and all of its uses, go here. Likewise, if you know Perl already, you can skip this section and go to "Getting Started - The HTML".

All variables start with a $. Well, that's not true. Perl has other types of variables, we just won't be using them. As a side note, if you are interested in the Perl language itself, visit your favorite computer bookstore and ask for the "Camel book" -- it's published by O'Reilly, has a camel on the front cover, and is the definitive reference on Perl. Variables can be as descriptive as you would like.

Examples:

$Customer 
$Employee1 
$Phone_number

To open a file, use the open command.

Syntax:

open(TAG, "path/to/file") 
     or die "Message to	print when 
             the file can't be opened";

TAG: A short phrase for referring to this file in other parts of the program.

path/to/file: This is where you need to know the path to your douments. In most cases this will just be the file's name (see example). This path varies widely on different systems. If you are not sure, contact your system administrator.

Message to print when the file can't be opened: Self explanatory. Use \n to print a new line. $! Prints the error message.

Example:

open(THEATER, "theater.data") 
   or die "We could not open the Movie 
          Theater Information file.\n 
          Please email the webmaster
          with the following 
          information:\n$!\n";

Note: Our examples are word wrapped for formatting purposes. All Perl lines end in a semicolon, so when using this code in your programs, make sure each line ends in a semicolon.

We'll be reading input from a file. Our file will have text seperated by semicolon. If this bothers you (or more importantly conflicts with some of your data, use a comma or some other character. After each file is opened, change the semicolon in the split statement to that character.

People will use your Perl program just as they do any HTML file - so you'll need to print your output in HTML. To do this:

Print >> EOF;
<PUT HTML HERE, USE AS MANY 
        LINES AS NEEDED>
EOF;

Also note: before the first part of your output, insert this line.

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


SQL etc Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
SQL etc Forum
Topic By Replies Updated
MySQL rollback UAL225 0 August 21st, 09:56 PM
Complex Search Query Galway 0 May 20th, 10:04 PM
change collation at once supercain 2 May 15th, 06:18 AM
SQL Features, tools and utilities question Neomite 1 April 10th, 09:13 AM