|
|
tylermenezes |
|
|
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
|
| |
|
|
|
|
|
Justin |
|
|
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
|
|
|
|
|
|
tylermenezes |
|
|
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. |
| |
|
|
|
|
|
Justin |
|
|
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
|
|
|
|
|
|
tylermenezes |
|
|
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? |
| |
|
|
|
|
|
Justin |
|
|
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  |
|
|
|
|
|
tylermenezes |
|
|
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) |
|
| |
|
|
|
|
|
|