Welcome to the E-Blah Community!
We would like to welcome you to our community and invite you to register an account or login.
Being a registered member is important, as it gives you several advantages over the normal Guest status. After registering you will be able to download files and images, post messages, and access member-only portions of the forum - just to name a few. Registration is quick and simple, and only takes about a minute of your time.

E-Blah Community    General Discussion    Chit - Chat  ›  Perl help!
Users Browsing Forum
No Members and 1 Guests

Perl help!  This thread currently has 810 views. Print
1 Pages 1 Recommend Thread
NapAiM
March 24, 2006, 12:20pm Report to Moderator Report to Moderator
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)


Logged Offline
Private Message Private message
Justin
March 24, 2006, 2:49pm Report to Moderator Report to Moderator

The E-Blah Developer
E-Blah Programmer
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
Hmm?  I'm not sure what you're talking about.  There is a diffrent value on each line.  I'm not following you (I am listening to Sean Hannity, so all my focus may be on that ... hmm ...).


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

Logged Offline
Site Site Private Message Private message Reply: 1 - 9
NapAiM
March 24, 2006, 4:31pm Report to Moderator Report to Moderator
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?


Logged Offline
Private Message Private message Reply: 2 - 9
Justin
March 24, 2006, 9:13pm Report to Moderator Report to Moderator

The E-Blah Developer
E-Blah Programmer
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

Logged Offline
Site Site Private Message Private message Reply: 3 - 9
NapAiM
March 25, 2006, 6:11am Report to Moderator Report to Moderator
E-Blah Member
Posts: 7
Posts Per Day: 0.01
Time Online: 3 hours 4 minutes
http://search.cpan.org/~mjd/Tie-File-0.96/lib/Tie/File.pm

that looks brilliant thank you, my problem was with append and read that read wont edit the file, append wont change anything and write deletes everything

but thanks allot


Logged Offline
Private Message Private message Reply: 4 - 9
Justin
March 25, 2006, 11:00am Report to Moderator Report to Moderator

The E-Blah Developer
E-Blah Programmer
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
< reads and writes.

The module looks nice, actually.


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

Logged Offline
Site Site Private Message Private message Reply: 5 - 9
NapAiM
March 26, 2006, 4:29pm Report to Moderator Report to Moderator
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?


Logged Offline
Private Message Private message Reply: 6 - 9
Justin
March 27, 2006, 8:25am Report to Moderator Report to Moderator

The E-Blah Developer
E-Blah Programmer
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
You have to use seek and truncate.


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

Logged Offline
Site Site Private Message Private message Reply: 7 - 9
NegativeZero
March 28, 2006, 8:55pm Report to Moderator Report to Moderator
http://www.canadascteam.com powered on EBlah
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.
Logged Offline
Site Site Private Message Private message Reply: 8 - 9
NapAiM
April 2, 2006, 9:37am Report to Moderator Report to Moderator
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



Logged Offline
Private Message Private message Reply: 9 - 9
1 Pages 1 Recommend Thread
Print

E-Blah Community    General Discussion    Chit - Chat  ›  Perl help!