|
|
NapAiM |
|
E-Blah Member 
Posts: 7
Posts Per Day: 0.01
Time Online: 3 hours 4 minutes
|
hello! i take some great imspitration from eblah, being the best Perl-bbased forum there is, a while back i decided to start work on my own website, its not a forum as such im thinking of making it into a game (one of those text based web games) only im having problems when it comes to users registering and editing, for example at the moment when an user posts a message it does this:
|
Code
$count = ($account[4] + 1); open(USR,">accts/members/$so_nick.acct"); $fprint = "$account[0]:$account[1]:$account[2]:$account[3]" . ':' . $count; print USR $fprint; print '<meta HTTP-EQUIV="REFRESH" content="0; url=./post.cgi">';
|
|
as you can probolly see here: $account[0]:$account[1]:$account[2]:$account[3]" . ':' . $count -- that line is absolutelly sick! that is simply to increase someones post count by one, it would be so so so much easier simply to find the line in the file with the persons post count say line 25 and change it only i dont have a clue how, you can open it in write mode > deleting everything or append >> that wond change it, all the others are read mode  I looked in the eblah source and saw that it puts the member details line by line into a file and i looked for a snippet of code and found this
|
Code
fopen(FILE,">$members/$URL{'u'}.dat"); for($q = 0; $q < $usersetcount; $q++) { print FILE "$userset{$URL{'u'}}->[$q]\n"; } fclose(FILE); |
|
im intrugied as to how this actually works, for($q = 0; $q < $usersetcount; $q++) { print FILE "$userset{$URL{'u'}}->[$q]\n"; } that line, as far as im aware it prints all their regitered details into that file line by line, can you then simply edit one line later on with a code not unlike that? Another thing that i am confused about is the including of files, im talking about settings.pl, can you just use require('file.extn'); and then it will load any variable like $url = lala.com; from that other file?? Thanks for your help and gj on the forum system -- Napalm (ps- i couildent see a coding place to post this but if there is one would you be so kind as to move it  thanks) |
| |
|
|
|
|
|
Justin |
|
|
Posts: 15,070
Gender:  Male
Posts Per Day: 6.55
Reputation: 93.40%
Reputation Score: +297 / -21
Time Online: 36 days 23 hours 14 minutes
Location: Tallassee, AL
Age: 22
|
|
|
|
|
|
NapAiM |
|
E-Blah Member 
Posts: 7
Posts Per Day: 0.01
Time Online: 3 hours 4 minutes
|
ok i shalt make it more clear lol your users are layed out in their files like so:
|
Code
User user@mail.com 0
1136914841 0
|
|
i would like to do that only i need a way to say edit only one part of the file, for example line 1 the users pass if they wanted to change it in mine where iots layed out like so:
|
Code
Napalm:$1$aG$OVZNQfBlislvTvn0/gVH6/:000.000.000.000:44 |
|
like in the format Nick:pass:IP:post count and i cant edit any single part of it, say they want to change pass i need to make that whole line Napalm:$1$aG$OVZNQfBlislvTvn0/gVH6/:000.000.000.000:44 = $line then split(/:/,$line) and then change one part of it and then write it back into the file again with the disgusting meathod: $line[0].':'.$line[1].':'.$line[2].':'.$Post_count++ its sick! what i want to do is simply edit one line of the file, like line 20 line 20 wouldent change, to get an users post count it would be on line 20, you would only open line 20 to edit it, i think that is what you do but im totally confused  am i making sense? |
| |
|
|
|
|
|
Justin |
|
|
Posts: 15,070
Gender:  Male
Posts Per Day: 6.55
Reputation: 93.40%
Reputation Score: +297 / -21
Time Online: 36 days 23 hours 14 minutes
Location: Tallassee, AL
Age: 22
|
I guess use seek() and truncate() would do that and open the file for read and write (< || +<). It'd be more difficult, but possible I suppose. But I think you'd have to get everything from the truncate forward into memory ... not sure. I don't use them much. The Perl man pages:
Quoted Text
How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file? Use the Tie::File module, which is included in the standard distribution since Perl 5.8.0.
From: perlfaq5 -- perlfaq5.html#how_do_i_change_one_line_in_a_file_delete_a_line_in_a_file_insert |
| I do installs for $25 and upgrades for $20.Technical support is always free. Donate to E-Blah! My Websites: Revolution Reality (My Blog) | MinistryTalk.com | Portfolio"But you, O Lord, are a compassionate and gracious God, slow to anger, abounding in love and faithfulness." — Psalm 86:15 NIV  |
|
|
|
|
|
NapAiM |
|
E-Blah Member 
Posts: 7
Posts Per Day: 0.01
Time Online: 3 hours 4 minutes
|
|
|
|
|
|
Justin |
|
|
Posts: 15,070
Gender:  Male
Posts Per Day: 6.55
Reputation: 93.40%
Reputation Score: +297 / -21
Time Online: 36 days 23 hours 14 minutes
Location: Tallassee, AL
Age: 22
|
|
|
|
|
|
NapAiM |
|
E-Blah Member 
Posts: 7
Posts Per Day: 0.01
Time Online: 3 hours 4 minutes
|
Quoted from admin
< reads and writes.
The module looks nice, actually.
so using < means i can open a file to read it and then change one part of it? |
| |
|
|
|
|
|
Justin |
|
|
Posts: 15,070
Gender:  Male
Posts Per Day: 6.55
Reputation: 93.40%
Reputation Score: +297 / -21
Time Online: 36 days 23 hours 14 minutes
Location: Tallassee, AL
Age: 22
|
|
|
|
|
|
NegativeZero |
|
|
Posts: 76
Posts Per Day: 0.04
Reputation: 100.00%
Time Online: 29 minutes
Location: Woodbridge
Age: 25
|
napaim, eblah uses two subroutines fopen and fclose which allow for file locking so that two people can't accidently access the file at the same time, they are designed to work almost exactly like open and close.
please note that those subroutines are unrecommended if you program in strict (which is suggested) because of the passing of the file handle to the subroutine. |
|
|
|
|
|
NapAiM |
|
E-Blah Member 
Posts: 7
Posts Per Day: 0.01
Time Online: 3 hours 4 minutes
|
Quoted from NegativeZero
napaim, eblah uses two subroutines fopen and fclose which allow for file locking so that two people can't accidently access the file at the same time, they are designed to work almost exactly like open and close.
please note that those subroutines are unrecommended if you program in strict (which is suggested) because of the passing of the file handle to the subroutine.
 thanks ill update my links |
| |
|
|
|
|
|
|