Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Writing to a text file

Reply
Thread Tools

Writing to a text file

 
 
Steven Mocking
Guest
Posts: n/a
 
      12-14-2003
Neil Trigger wrote:

> Is there a way of creating a seperate text file on a server every time a
> form is sent?


Certainly, but why don't you use a database? A clogged up directory full
of thousands of text-files bites you in the end.

--
Nobody ever forgets where he buried the hatchet.
-- Kin Hubbard
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      12-14-2003
Neil Trigger wrote:
> Is there a way of creating a seperate text file on a server every
> time a form is sent?


Where is the problem?

jue


 
Reply With Quote
 
 
 
 
Nick Santos
Guest
Posts: n/a
 
      12-14-2003

"Neil Trigger" <> wrote in message
news:KKWCb.54752$...
> Is there a way of creating a seperate text file on a server every time a
> form is sent?
>


I agree. I recently wrote a website that requires lots of coding and lots of
forms. Each form did a lot of text file reading and writing. I only have
about 30 users (who can use forms multiple times), but I have about 650
files and 450 folders for this. It's not the way to go. I've been slowly
switching it over to MySQL.

But to answer your question, yes. Therea are two ways you could do it
(assuming they aren't logged in. If they are logged in then you can do many
more). But If they aren't logged in, you can create a text file by ip
address, or text files can be created sequentially. You can also creat it
using any other data that you have on the user. If you create it by ip
address, you will want to append to the file if the user is allowed to
submit the form multiple times.

#_BEGIN_
# this is a demonstration of using the ip address to do it
# the ip address can be gotten using the following variable
$ENV{'REMOTE_ADDR'}

open (OUTF, ">>$ENV{'REMOTE_ADDR'}.txt"); #appending to prevent data loss
print OUTF "data";
close (OUTF);

#_END_

That is definitely the simpler one, assuming that the people aren't
submitting it multiple times.

#_BEGIN_
# This is a demonstration of making a text file by sequential numbering

opendir (DIR, "filedir");
@dir = readdir (DIR); #get all the files in the directory's names
closedir (DIR);

$end = @dir;
$i = 2; #we start i at two because of the . and .. entries in the directory

while($i<$end){
if(@dir[$i] =~ /\d.txt/){ #count the number of files in the directory
that are already made by this program
$n++; #n will eventually be the digit we use in the filename
}
$i++;
}

open (OUTF, ">>$n.txt"); #still good to append just to prevent data loss
print OUTF "data";
close (OUTF);

#_END_

that one will create a seperate file and number them sequentially. If you
remove files from the directory though, be careful because it could start
writing in other ones and you won't know. If you want to be able to remove
files and have it still continure after the last one, then we'd check the
whole array using regular expressions for what the highest one is. I won't
put code for that here because I'm not sure if you'll be able to use it, and
I'm fairly bad at regular expressions. However, if you do decide you could
use it, I'd be happy to post some code.
-Nick


 
Reply With Quote
 
Chris W
Guest
Posts: n/a
 
      12-14-2003
Steven Mocking wrote:
>
> Neil Trigger wrote:
>
> > Is there a way of creating a seperate text file on a server every time a
> > form is sent?

>
> Certainly, but why don't you use a database? A clogged up directory full
> of thousands of text-files bites you in the end.


I agree, but if you have an application that doesn't see very heavy use
and don't have a db on the server you are using like this one project I
have done. What you can do is have your script get the time then append
000 to the end, then try to open for reading a file of that name, if it
opens you know it already exist so then move on to 001 and see if that
exists, keep going till find a file that doesn't exist and then create
it. This isn't the best solution and will cause problems if it has
heavy use but for simple projects that are low usage it works fine.
Another option would be to append the IP address of the incoming request
and the port number the client is using although I'm not sure how to
find the port the client is sending on but there must be a way.

Chris W
 
Reply With Quote
 
Alex Zeng
Guest
Posts: n/a
 
      12-14-2003
Use time stamp as a filename.

"Neil Trigger" <> wrote in message
news:KKWCb.54752$...
> Is there a way of creating a seperate text file on a server every time a
> form is sent?
>
> --
> ¿ Trigger ?
> http://www.magic2k.com/
> http://www.oddmap.co.uk
>
>



 
Reply With Quote
 
Neil Trigger
Guest
Posts: n/a
 
      12-14-2003
Is there a way of creating a seperate text file on a server every time a
form is sent?

--
¿ Trigger ?
http://www.magic2k.com/
http://www.oddmap.co.uk


 
Reply With Quote
 
Nick Santos
Guest
Posts: n/a
 
      12-14-2003
very true. I'd forgotten about that one. thanks


 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      12-14-2003
[fullquote]
Nick Santos wrote:
> very true.


What is true?

> I'd forgotten about that one.


What did you forget about?

>thanks


Thanks for what?

Without some sort of context your statement is incomprehensible.

jue


 
Reply With Quote
 
Nick Santos
Guest
Posts: n/a
 
      12-14-2003
"Jürgen Exner" <> wrote in message
news:985Db.13855$...
> [fullquote]
> Nick Santos wrote:
> > very true.

>
> What is true?
>
> > I'd forgotten about that one.

>
> What did you forget about?
>
> >thanks

>
> Thanks for what?
>
> Without some sort of context your statement is incomprehensible.
>
> jue


I'd forgotten about using a timestamp as a filename. one sure way to not get
overwrites as long as it's specified well enough. I don't usually delete the
content, but for some reason I did with that one. Sorry about that


 
Reply With Quote
 
Neil Trigger
Guest
Posts: n/a
 
      12-15-2003
Thank you all for your advise. I thought that the text file'd be the best
way, but upon reflection I think a database might be the best way. I have a
MySQL database system thing on my webserver that I've not played with to any
great (or very clever) extent.
Would I need to subscribe to alt.database.integration or something and ask
them? ;o)

--
¿ Trigger ?
http://www.magic2k.com/
http://www.oddmap.co.uk


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET form action file - writing to text file icedragon ASP .Net 0 07-13-2010 01:48 PM
Writing a text file to the file system =?Utf-8?B?Y3dicDE1?= ASP .Net 5 10-29-2005 10:39 AM
Writing a text file to the file system =?Utf-8?B?Y3dicA==?= ASP .Net 0 03-21-2005 11:09 PM
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM
Question: Writing text file based TestBenches vs. Waveform file based simulation. BLF VHDL 4 08-07-2004 12:44 AM



Advertisments