CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Writing to a text file



Apr 22, 2002, 8:54 AM

Post #1 of 4 (403 views)
Writing to a text file Can't Post

I have the following question. It's a bit confusing so please try to keep up.

I have a ascii text database that has about 1400 records. For every record in this database, there is a seperate text file that has a description for that record. The name of these individual text files are named exactly as the item_id from the original database.

I would like to join all the 1400 text files together with the original database into a new database.

Here is an example:

Here is what the original database looks like.  

1245|Item A|Category 6
1464|Item B|Category 4

This would be the 2 seperate text file.

filename: 1245.txt
1245|This is the description for 1245

filename: 1464.txt
1464|This is the description for 1464

This is what I would like to happen with the new database.

1245|Item A|Category 6|This is the description for 1245
1464|Item B|Category 4|This is the description for 1464

I hope you understand.



Apr 22, 2002, 9:57 AM

Post #2 of 4 (401 views)
Re: [JFrost] Writing to a text file [In reply to] Can't Post

So what's your question? Where's the work you've put in so far?



(This post was edited by dsb on Apr 22, 2002, 9:58 AM)


Apr 22, 2002, 10:24 AM

Post #3 of 4 (398 views)
Re: [dsb] Writing to a text file [In reply to] Can't Post

I have not done anything yet. I was hoping I would be told on how to structure a loop that will do this.

Thanks again


Apr 23, 2002, 12:19 AM

Post #4 of 4 (390 views)
Re: [JFrost] Writing to a text file [In reply to] Can't Post

The structure might be al following:


my @new_file;

open <main file;

while (<main file>) {

get the description file and the rest of the fields;

open <description file;

get the description;

push(@new_file, $all, $the, $relevant, $fields, $from, $both, $files);

close description file;


close main file;

open >main file;

write the contents of the @new_file to the main file;

close main file;

Hope this clarifies something...

Jean Spector
SQA Engineer @ Exanet

There are only 10 types of people in the world -
Those who understand binary, and those who don't.

(This post was edited by Jean on Apr 23, 2002, 12:19 AM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives