Solved

Script to read the database and create pages for each record in the database.

Posted on 2004-08-08
20
166 Views
Last Modified: 2010-03-05
I have several products I need to provide a download page for. Each page has basically the same information except URL, title, and name of product the URL points to.

What is the code that will allow me to create a flat file database where I can put a file hadle, name of product, URL, HTML page separated by a charater like this:

QUEST | eBay Marketing Secrets | https://supersys2000.com/SUPERPAK_2/ebay.zip | ebay_zip.html

I won't the script to read the database and create pages for each record in the database. How do I do that?

Thanks,
0
Comment
Question by:QUESTOMNI
  • 12
  • 8
20 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 11749497
To create it, do:

my $dbfile='/path/to/file';
open DB, ">>$dbfile" or die "Can not open $dbfile $!\n";
print DB "QUEST | eBay Marketing Secrets | https://supersys2000.com/SUPERPAK_2/ebay.zip | ebay_zip.html\n";
close DB;
0
 

Author Comment

by:QUESTOMNI
ID: 11749706
QUEST | eBay Marketing Secrets | https://supersys2000.com/SUPERPAK_2/ebay.zip | ebay_zip.html

That is one of the records. Here are more records:

QUEST| eBay Marketing Secrets | https://supersys2000.com/SUPERPAK_2/ebay.zip |ebay_zip.html
QUEST1| Classified Ad Secrets |https://supersys2000.com/SUPERPAK_2/classified.zip |classified_zip.html
QUEST2| Credit Secrets | https://supersys2000.com/SUPERPAK_2/credit.zip | credit_zip.html
QUEST3| Wholesale sources | https://supersys2000.com/SUPERPAK_2/wholesale.zip | wholesale_zip.html
QUEST4| Self-publish at the Speed of Thought | https://supersys2000.com/SUPERPAK_2/thought.exe | thought_exe.html

I have 30 records in all. I want a webpage for each created from my database. QUEST is the name of the file handle, then name of the product, then URL, then name of file to create.

Here is the webpage templet:


<HTML
<HEAD>
  <META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Win">
  <TITLE>NAME_00</TITLE>
</HEAD>
<BODY ALINK="#800080" VLINK="#00ffff" BGCOLOR="#005100">

<P><CENTER><TABLE WIDTH="350" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17"><P><CENTER>&nbsp;<A HREF="http://supersys2000.com/images/supersystem2.jpg"
TARGET="_top"><IMG SRC="http://supersys2000.com/images/supersystem2.jpg"
ALIGN="BOTTOM" BORDER="0"></A></CENTER></TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
</TABLE>


</CENTER></P>

<H2><CENTER><FONT COLOR="#00e8e8">NAME_00 DOWNLOAD</FONT></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><A HREF="URL"
TARGET="_top">NAME_00</A></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><FONT COLOR="#00e8e8">ENJOY!</FONT> </CENTER></H2>
</BODY>
</HTML

0
 
LVL 48

Expert Comment

by:Tintin
ID: 11749784
my $dbfile='/path/to/file';
open DB, $dbfile or die "Can not open $dbfile $!\n";

while (<DB>) {
  chomp;
   my ($handle,$product,$url,$file) = split(/\|/);
   open FILE, ">$file" or die "Can not create $file $!\n";

   print FILE <<EOF;
 <HTML
<HEAD>
  <META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Win">
  <TITLE>$Product</TITLE>
</HEAD>
<BODY ALINK="#800080" VLINK="#00ffff" BGCOLOR="#005100">

<P><CENTER><TABLE WIDTH="350" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17"><P><CENTER>&nbsp;<A HREF="http://supersys2000.com/images/supersystem2.jpg"
TARGET="_top"><IMG SRC="http://supersys2000.com/images/supersystem2.jpg"
ALIGN="BOTTOM" BORDER="0"></A></CENTER></TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
</TABLE>


</CENTER></P>

<H2><CENTER><FONT COLOR="#00e8e8">NAME_00 DOWNLOAD</FONT></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><A HREF="$url"
TARGET="_top">NAME_00</A></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><FONT COLOR="#00e8e8">ENJOY!</FONT> </CENTER></H2>
</BODY>
</HTML
EOF

  close FILE;
}
0
 

Author Comment

by:QUESTOMNI
ID: 11749953
IT'S NOT PRINTING. I MADE SURE THE FOLDER WAS 755 THE WEBPAGES ARE TO BE CREATED IN AND STILL CAN'T GET SCRIPT TO WORK.

COULD IT BE YOU ARE USING ONE FILE HANDLE FOR ALL PAGES? HOW CAN WE HAVE THE FILE HANDLE TO CHANGE FOR EACH PAGE TO BE CREATED. I DID TRY TO ACCOUNT FOR THAT IN MY DATABASE. HOW WOULD USE THEM? THEY ALL START WITH "QUEST"
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11750006
What is your definition of a "file handle"?  I suspect it is different from the common meaning.

How are you determining it is not "printing" (I assume you mean creating the file)?  Do you get any error messages?
0
 

Author Comment

by:QUESTOMNI
ID: 11750193
The file handle replaces the address of the actual file.

It's not creating the files and I get no error message.
0
 

Author Comment

by:QUESTOMNI
ID: 11750239
Here's what I'm scripting as you suggested:

#!/usr/local/bin/perl5.00502
print "Content-type:text/html\n\n";

open(DB, "/home/wh36824/public_html/EBOOK_PROCESS/freetosell_ebooks_createsites.db") or dienice("Can't open DB: $1 \n");
while (<DB>) {
  chomp;
   my ($handle,$product,$url,$file) = split(/\|/);
   open FILE, ">/home/wh36824/public_html/EBOOKS/$file" or die "Can not create $file $!\n";

 print FILE <<EOF;
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Win">
<TITLE>$product</TITLE>
</HEAD>
<BODY ALINK="#800080" VLINK="#00ffff" BGCOLOR="#005100">

<P><CENTER><TABLE WIDTH="350" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17"><P><CENTER>&nbsp;<A HREF="http://supersys2000.com/images/supersystem2.jpg"
TARGET="_top"><IMG SRC="http://supersys2000.com/images/supersystem2.jpg"
ALIGN="BOTTOM" BORDER="0"></A></CENTER></TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
</TABLE>


</CENTER></P>

<H2><CENTER><FONT COLOR="#00e8e8">$product DOWNLOAD</FONT></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><A HREF="$url"
TARGET="_top">$product</A></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><FONT COLOR="#00e8e8">ENJOY!</FONT> </CENTER></H2>
</BODY>
</HTML>
EOF

  close FILE;
}

0
 
LVL 48

Expert Comment

by:Tintin
ID: 11758976
Are you saying that there are *NO* files at all created under /home/wh36824/public_html/EBOOKS?

I find that very difficult to believe if you don't get any errors running the script.
0
 

Author Comment

by:QUESTOMNI
ID: 11759473
Right, No files at all created under /home/wh36824/public_html/EBOOKS?
I can't see why. There are several pages being created at the same time. It may need delays of some type.
0
 

Author Comment

by:QUESTOMNI
ID: 11759477
Did you try it on your server?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 48

Expert Comment

by:Tintin
ID: 11759491
Yes, I ran it on my server and it works perfectly.

Using your sample DB, I have the following files created:

ebay_zip.html
classified_zip.html
credit_zip.html
wholesale_zip.html
thought_exe.html

What do you mean "there are several pages being created at the same time"?
0
 

Author Comment

by:QUESTOMNI
ID: 11759525
Please show me the exact script you used and tell me what folder you ran the script from.
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 11759629
I ran it from the command line in my home directory

#!/usr/bin/perl

my $dbfile='dbfile';
open DB, $dbfile or die "Can not open $dbfile $!\n";

while (<DB>) {
  chomp;
   my ($handle,$product,$url,$file) = split(/\|/);
   open FILE, ">$file" or die "Can not create $file $!\n";

   print FILE <<EOF;
 <HTML
<HEAD>
  <META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Win">
  <TITLE>$Product</TITLE>
</HEAD>
<BODY ALINK="#800080" VLINK="#00ffff" BGCOLOR="#005100">

<P><CENTER><TABLE WIDTH="350" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17"><P><CENTER>&nbsp;<A HREF="http://supersys2000.com/images/supersystem2.jpg"
TARGET="_top"><IMG SRC="http://supersys2000.com/images/supersystem2.jpg"
ALIGN="BOTTOM" BORDER="0"></A></CENTER></TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
</TABLE>


</CENTER></P>

<H2><CENTER><FONT COLOR="#00e8e8">NAME_00 DOWNLOAD</FONT></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><A HREF="$url"
TARGET="_top">NAME_00</A></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><FONT COLOR="#00e8e8">ENJOY!</FONT> </CENTER></H2>
</BODY>
</HTML
EOF

  close FILE;
}
0
 

Author Comment

by:QUESTOMNI
ID: 11759753
Please run it from a folder in which the pages are to be create. I am unfamiliar with command line operations on my system.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11767783
I run it both ways, from the command line and from the browser and it works perfectly for all cases.

You still haven't answered my question:

"What do you mean "there are several pages being created at the same time"?
0
 

Author Comment

by:QUESTOMNI
ID: 11790717
Sorry for not getting back to you until now. I had several personal matters to attend to and have been trying to find out about Telnet access to my server.

What I mean about several pages being created at the same time is each record has one page being created for it if the script works properly. They may not be the same exact time but near the same time. I misspoke. There could be something wrong with my service. I should be able to get back to you tomorrow.  

Thanks
0
 

Author Comment

by:QUESTOMNI
ID: 11790803
What is wrong with my script? It's not working. My perl debugger says it's good.

*************************************

#!/usr/bin/perl
print "Content-type:text/html\n\n";


my $dbfile= '/home/wh36824/public_html/EBOOKS/freetosell_ebooks_createsites.db';
open (DB, "$dbfile") or die "Can not open $dbfile $!\n";

while (<DB>) {
  chomp;
   my ($handle,$product,$url,$file) = split(/\|/);
   open FILE, ">$file" or die "Can not create $file $!\n";

print FILE <<EOF;
<HTML
<HEAD>
  <META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Win">
  <TITLE>$product</TITLE>
</HEAD>
<BODY ALINK="#800080" VLINK="#00ffff" BGCOLOR="#005100">

<P><CENTER><TABLE WIDTH="350" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17"><P><CENTER>&nbsp;<A HREF="http://supersys2000.com/images/supersystem2.jpg"
TARGET="_top"><IMG SRC="http://supersys2000.com/images/supersystem2.jpg"
ALIGN="BOTTOM" BORDER="0"></A></CENTER></TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
</TABLE>


</CENTER></P>

<H2><CENTER><FONT COLOR="#00e8e8">NAME_00 DOWNLOAD</FONT></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><A HREF="$url"
TARGET="_top">NAME_00</A></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><FONT COLOR="#00e8e8">ENJOY!</FONT> </CENTER></H2>
</BODY>
</HTML
EOF

  close FILE;
}

0
 
LVL 48

Expert Comment

by:Tintin
ID: 11805669
There's nothing wrong with the script.  The "problem" must be elsewhere.
0
 

Author Comment

by:QUESTOMNI
ID: 11941684
Someone please write me a script that creates my HTML page for each record in the flat file database.

Here is the database:


QUEST| eBay Marketing Secrets | https://supersys2000.com/SUPERPAK_2/ebay.zip |ebay_zip.html
QUEST1| Classified Ad Secrets |https://supersys2000.com/SUPERPAK_2/classified.zip |classified_zip.html
QUEST2| Credit Secrets | https://supersys2000.com/SUPERPAK_2/credit.zip | credit_zip.html
QUEST3| Wholesale sources | https://supersys2000.com/SUPERPAK_2/wholesale.zip | wholesale_zip.html
QUEST4| Self-publish at the Speed of Thought | https://supersys2000.com/SUPERPAK_2/thought.exe | thought_exe.html
QUEST5| A Cheap and Easy Guide To Self-publishing eBooks| https://supersys2000.com/SUPERPAK_2/selfpub.exe | selfpub_exe.html
QUEST6| Your eBook Daily Marketing Plan | https://supersys2000.com/SUPERPAK_2/edmplan.exe | edmplan_exe.html
QUEST7| How to be a Mystery Shopper | https://supersys2000.com/SUPERPAK_2/mysteryshopper.exe | mysteryshopper_exe.html
QUEST8| UK-Traders UK Wholesale guide | https://supersys2000.com/SUPERPAK_2/wholesalejan2002.exe | wholesalejan2002_exe.html
QUEST9| Living off the Net | https://supersys2000.com/SUPERPAK_2/living.zip | living_zip.html
QUEST10| Working with ClickBank | https://supersys2000.com/SUPERPAK_2/clickbook.pdf | clickbook_pdf.html
QUEST11| Million Dollar emails | https://supersys2000.com/SUPERPAK_2/mde.zip | mde_zip.html

QUEST12| Professional Cover Creation Tutorial  | https://supersys2000.com/SUPERPAK_2/ebct1.exe | ebct1_exe.html
QUEST13| Covers1| https://supersys2000.com/SUPERPAK_2/Covers1.zip | Covers1_zip.html
QUEST14| Covers2| https://supersys2000.com/SUPERPAK_2/Covers2.zip | Covers2_zip.html
QUEST15| Text-to-Speech Engine | https://supersys2000.com/SUPERPAK_2/TTS.zip | TTS_zip.html

QUEST16| Internet Cash Machines | https://supersys2000.com/SUPERPAK_2/cashmachines.zip | cashmachines_zip.html
QUEST17| 1001 Newbie-Friendly Tips  | https://supersys2000.com/SUPERPAK_2/tipspdf.zip | tipspdf_zip.html
QUEST18| AutoResponder Magic | https://supersys2000.com/SUPERPAK_2/autorespondermagic.zip | autorespondermagic_zip.html
QUEST19| E-Mail Marketing Strategies | https://supersys2000.com/SUPERPAK_2/email.exe | email_exe.html
QUEST20| eBay Marketing eCourse | https://supersys2000.com/SUPERPAK_2/ebayms.zip | ebayms_zip.html
QUEST21| The Internet Marketers Secret Guide | https://supersys2000.com/SUPERPAK_2/marketer.exe | marketer_exe.html
QUEST22| The Ultimate eLibrary | https://supersys2000.com/SUPERPAK_2/elib.exe | elib_exe.html
QUEST23| InterNETACTIVE | https://supersys2000.com/SUPERPAK_2/ina.zip | ina_zip.html
QUEST24| iNet Success  | https://supersys2000.com/SUPERPAK_2/inet.exe | inet_exe.html
QUEST25| The eBook Cover Templates | https://supersys2000.com/SUPERPAK_2/ebcover.exe | ebcover_exe.html
QUEST26| The Cash Flow e-Business | https://supersys2000.com/SUPERPAK_2/cashflow.exe | cashflow_exe.html
QUEST27| The Complete Guide to Building Your Own Web Site  | https://supersys2000.com/SUPERPAK_2/byows.exe | byows_exe.html
QUEST28| Free eZine Ad System  | https://supersys2000.com/SUPERPAK_2/freeadsystem.exe | freeadsystem_exe.html
QUEST29| Pay-Per-Click Commando  | https://supersys2000.com/SUPERPAK_2/ppccommando.exe | ppccommando_exe.html
QUEST30| Millionaire Marketing  | https://supersys2000.com/SUPERPAK_2/millionaire_marketing.zip  | millionaire_marketing_zip.html

***************************************************
Here is the page I want created:

<HEAD>
  <META NAME="GENERATOR" CONTENT="Adobe PageMill 2.0 Win">
  <TITLE>$product</TITLE>
</HEAD>
<BODY ALINK="#800080" VLINK="#00ffff" BGCOLOR="#005100">

<P><CENTER><TABLE WIDTH="350" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17"><P><CENTER>&nbsp;<A HREF="http://supersys2000.com/images/supersystem2.jpg"
TARGET="_top"><IMG SRC="http://supersys2000.com/images/supersystem2.jpg"
ALIGN="BOTTOM" BORDER="0"></A></CENTER></TD></TR>
<TR>
<TD WIDTH="100%" BGCOLOR="#002f17">&nbsp;</TD></TR>
</TABLE>


</CENTER></P>

<H2><CENTER><FONT COLOR="#00e8e8">NAME_00 DOWNLOAD</FONT></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><A HREF="$url"
TARGET="_top">NAME_00</A></CENTER></H2>

<H2><CENTER>&nbsp;</CENTER></H2>

<H2><CENTER><FONT COLOR="#00e8e8">ENJOY!</FONT> </CENTER></H2>
</BODY>
</HTML
EOF
0
 

Author Comment

by:QUESTOMNI
ID: 11960613
Hello  Tintin,

Thank you very much for the time you spent with me and getting me as far as you did. You might take a look at what  FishMonger did on the other question I entered to solve the problem. It worked the first time out of the gate. I'm amazed at the work you guys do and very thankful for the help given.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now