|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Wierd File-Reading Problem
I am working on a CGI script for my member site. What I am doing is having it create a seperate file for every member and then hold all of his variables, one to a line, in it. I do this by including a \n after every variable when it is written to the file.
Then, in the display subroutine, I pull all of the variables straight into the hash and display them on the screen. However, the \n seems to be included along with the variable and when it is printed out onto the page, everything on the line after the variable is shifted to the next line. This is creating several problems and I would like to know why this is happening and how to fix it. I am an not sure why this happens because I thought \n would only appear as a return in the file and then not be included in the variable. Has this happened to anyone else before? Can you help me out? Thanks, Leon |
|
#2
|
||||
|
||||
|
look into chomp(). You need to get rid of those newlines.
This seems like the hard way to deal with tracking member information, creating one file per user. The other thing- you'll be impeding your speed if you have many files (you could (hopefully!) have thousands of members, right?) in a single directory, each open will take longer. One other wrinkle- simultaneous accesses- If the same file is read/written by the same/different users, you could get corruption or lost data if you aren't very careful about file locking. You should probably use a rdbms (like mySQL) to track your users. This would take care of your speed, file locking, and potential scalability problems down the road should your site grow. Good luck! |
|
#3
|
|||
|
|||
|
Thanks alot.
I'll make sure to look into chomp. It seems like just what I need. What I am doing is severly modifying a free member script I found on the net. It used a standard flat-file database when I got it but that method wasn't able to hold enough information. So I am doing this my way. I would think that creating one file per user would be a better solution than that. Yes, I do hope that I will have thousands of members someday. Also, I didn't know that the more files in a directory, the longer it takes to access them. Thats interesting, but a solution would be incredably easy. If it comes to that I am sure that I can fix it. The simultaneous access thing is also actually better in my version. Because if you use a single flat-file then only one member can be editing anything at one time. Here every member can edit their own account and the chances of two people editing the same account is almost nil. I would use mySQL except that I can't afford it. The host that I am using doesn't offer mySQL support and I can't afford one that can. Also, wouldn't I need to learn a whole new mySQL syntax to use it? Plus, I would have to completely reconfigure my entire program to do it. Thanks, Leon |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Wierd File-Reading Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|