adding more fields to a database - painlessly (Posted by fairhousing)

They have: 1,587 posts

Joined: Mar 1999

hello:

the database i use has information stored in the following manner on a text file, one line per account:

account¦0¦0¦0¦0¦0¦0¦0¦0¦0¦0¦0¦0¦0¦0¦0¦0¦0

how would i go about adding more ¦0 to the end of the above string to increase the fields in the database without having to do it manually?

thanks in advance Wink

----------
My Site Got Hacked, Check It Out!
http://www.birminghamnet.com

Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?

They have: 69 posts

Joined: Apr 1999

You want to add more fields to every entry? Code:

# The number of fields you wanna add
$fields = 5;
# The filename of the database
$file = "database.txt";
# ----------------------------------

open (F, $file);
@db = <F>;
close F;

open (F, ">$file");
for (@db) {
$line = $_;
$line =~ s/\n//g;
for (0..$fields) { $line .= "¦0"; }
print F "$line\n";
}
close F;

print "Content-type: text/html\n\n";
print "$fields fields were added to each entry in the database";

As always, haven't tested it, but it should work fine.

Regards,
Federico Carnales

----------
Reviews of the best resources for webmasters in your e-mail every week!
Subscribe for [red]FREE[/red] by going to http://www.web-reviews.com/

They have: 1,587 posts

Joined: Mar 1999

thanks, i'll test it out.

thanks again Wink

----------
My Site Got Hacked, Check It Out!
http://www.birminghamnet.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.