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  ›  |||\n Problem
Users Browsing Forum
No Members and 1 Guests

|||\n Problem  This thread currently has 420 views. Print
1 Pages 1 Recommend Thread
tylermenezes
January 30, 2007, 5:59pm Report to Moderator Report to Moderator

Anybody here speak Python? HHHSSSSSSSSSSSSSS!
Posts: 201
Gender: Male
Posts Per Day: 0.21
Reputation: 90.48%
Reputation Score: +19 / -2
Time Online: 1 days 5 hours 56 minutes
Location: Redmond, Washington
Age: 16
I'm having a problem with a PERL program Justin helped write. The code is:

Code
sub deleteuser{
$td = shift;
$openfile = "$dir/list.txt";
open(LST,"$openfile");
@memberdb = <LST>;
close (LST);
open(LIST,">$openfile");
foreach $arraystring (@memberdb) {	
	($username,$quarter,$dateisued,$lunch) = split(/\|/,$arraystring);
	if($username eq $td) { next; }
	push(@usernames, $username);
	push(@quarters, $quarter);
	push(@dateissueds, $dateisued);
	push(@lunches, $lunch);
	print LIST "\n$username|$quarter|$dateisued|$lunch";
}
close(LIST);
}


The problem with the code is that every time I execute the command it creates a line of ||| and a new blank line. Not too much trouble but after a day the file grew to 100MB, because it's executed every time a user performs certain tasks.

Could somebody tell me what's wrong, and what I should do? BTW: Here's a copy of the file after two user additions...

Quoted Text


|||

|||

|||

|||
Taylor Love|3||2
*****|3||2


Logged Offline
Site Site Private Message Private message
Justin
January 30, 2007, 6:47pm Report to Moderator Report to Moderator

The E-Blah Developer
E-Blah Programmer
Posts: 15,075
Gender: Male
Posts Per Day: 6.52
Reputation: 93.40%
Reputation Score: +297 / -21
Time Online: 36 days 23 hours 27 minutes
Location: Tallassee, AL
Age: 22
... where's your chmop at?


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 - 6
tylermenezes
January 30, 2007, 7:24pm Report to Moderator Report to Moderator

Anybody here speak Python? HHHSSSSSSSSSSSSSS!
Posts: 201
Gender: Male
Posts Per Day: 0.21
Reputation: 90.48%
Reputation Score: +19 / -2
Time Online: 1 days 5 hours 56 minutes
Location: Redmond, Washington
Age: 16
I'm sorry? Not really sure what CHMOP is. Did you mean CHOMP? Still not really sure what that is, but I know it's a function in Perl.

Anyways, that's everything that I use to delete members. It works, except for that |||\n thing.


Logged Offline
Site Site Private Message Private message Reply: 2 - 6
Justin
January 30, 2007, 8:12pm Report to Moderator Report to Moderator

The E-Blah Developer
E-Blah Programmer
Posts: 15,075
Gender: Male
Posts Per Day: 6.52
Reputation: 93.40%
Reputation Score: +297 / -21
Time Online: 36 days 23 hours 27 minutes
Location: Tallassee, AL
Age: 22
Yes, chomp.  I had it in my examples in the other post.  Do that to the arrays.


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 - 6
tylermenezes
January 30, 2007, 8:39pm Report to Moderator Report to Moderator

Anybody here speak Python? HHHSSSSSSSSSSSSSS!
Posts: 201
Gender: Male
Posts Per Day: 0.21
Reputation: 90.48%
Reputation Score: +19 / -2
Time Online: 1 days 5 hours 56 minutes
Location: Redmond, Washington
Age: 16
This is what you meant, correct?

Code
sub deleteuser{
$td = shift;
$openfile = "$dir/list.txt";
open(LST,"$openfile");
@memberdb = <LST>;
close (LST);
open(LIST,">$openfile");
chomp @memberdb;
foreach $arraystring (@memberdb) {	
	($username,$quarter,$dateisued,$lunch) = split(/\|/,$arraystring);
	if($username eq $td) { next; }
	push(@usernames, $username);
	push(@quarters, $quarter);
	push(@dateissueds, $dateisued);
	push(@lunches, $lunch);
	print LIST "\n$username|$quarter|$dateisued|$lunch";
}
close(LIST);
}


Because it works... Thanks!

BTW: What does Chomp do, in a general sense?


Logged Offline
Site Site Private Message Private message Reply: 4 - 6
Justin
January 30, 2007, 8:43pm Report to Moderator Report to Moderator

The E-Blah Developer
E-Blah Programmer
Posts: 15,075
Gender: Male
Posts Per Day: 6.52
Reputation: 93.40%
Reputation Score: +297 / -21
Time Online: 36 days 23 hours 27 minutes
Location: Tallassee, AL
Age: 22
Do it before the open.  Also, try to format your code in the future so it's easier to read.    Not saying to use comments, as I don't even do that ... haha.

And don't do \n... do ...\n.  A \n before will only make the first line be garbage.  Why in the world are you doing shift?  You need that to be the user's actual name, not some command that modifies an array.  


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 - 6
tylermenezes
January 30, 2007, 9:20pm Report to Moderator Report to Moderator

Anybody here speak Python? HHHSSSSSSSSSSSSSS!
Posts: 201
Gender: Male
Posts Per Day: 0.21
Reputation: 90.48%
Reputation Score: +19 / -2
Time Online: 1 days 5 hours 56 minutes
Location: Redmond, Washington
Age: 16
The code is only for myself, and once I finish, I'll probably rarely update it, so not much need for comments. Thanks for the tip about the \n too.

As for the shift thing, I used it because I found it in another code sample. It does work with names, I call deleteuser($username); and it works.

Thanks again for all the help with this project. Not very many people I know even know what PERL does, and I'm sure those who do wouldn't be very willing to teach me anything.


Hey, just curious, where is the code that allows for different time zones located in E-Blah. I need to get that set up on mine. Thanks.



Revision History (1 edits)
tylermenezes  -  January 30, 2007, 9:57pm
Logged Offline
Site Site Private Message Private message Reply: 6 - 6
1 Pages 1 Recommend Thread
Print

E-Blah Community    General Discussion    Chit - Chat  ›  |||\n Problem