Gossamer Forum
Home : General : Perl Programming :

Complicated Requirements

Quote Reply
Complicated Requirements
Hello!

I think some posted with similar script with mine but can't find it.

I have a directory /home/account with subdirectories looks like

/home/account/user1
user2
user3

in each user directory they have a filename "info.txt". In that info.txt file it contains like this

Name: Jay Byrne
Location : Usa
Education : Undergrad
......
.....

How can I convert that all the info.txt files of each users into one flatfile like

Name|Location|Education
Jay|USA|Undergrad
...|...|....
...|...|....


I think the script should read each directory and open the info.txt and extract each information then read another directory till it reaches end of file right? Anyone who have done this before? plsss

thanks
Quote Reply
Re: Complicated Requirements In reply to
Looks like
for ($i=0;$i<$dircount;$i++)
{
$filetoread = '/pathtousers/user' & $dircount & 'info.txt';

open(USERS,"$filetoread");
until (eof(USERS))
{
$line=<USERS>;
@entry=split(/:/,$line);
if ($entry[0] eq "Name") {$name = $entry[1];}
if ($entry[0] eq "Grad") {$grad = $entry[1];}
if ($entry[0] eq "WhatUneed") {$dat = $entry[1];}
}
close(USERS);
open(NEWUSERS,">>database.txt");
print NEWUSERS "$name|$grad|$dat\n";
close(NEWUSERS);
}
Quote Reply
Re: Complicated Requirements In reply to
Thanksss..!!! Gonna try this later. I'll keep in touch

Quote Reply
Re: Complicated Requirements In reply to
Hello there!

I run the script on my server and it has no error however there is no output. the database.txt still empty. Did I miss anything?
Quote Reply
Re: Complicated Requirements In reply to
Anyone pls...
Quote Reply
Re: Complicated Requirements In reply to
This what written for extracting from a specific format, but I'm sure you could easily adjust the coding using also what shindi provided for your format to see what might be needed to make this work:

http://www.gossamer-threads.com/scripts/forum/resources/Forum5/HTML/000351.html

Hope this helps Smile
Quote Reply
Re: Complicated Requirements In reply to
Thanks for the Help LoisC however, I'm poor in cgi/perl programming though i'm trying to re-inventing the wheel but no luck. The code of shindi seems to be fine to me (a not so so programmer).

Still looking for lots of references/resources to make it run.
Thanks