Print Topic - Archive

E-Blah Community  /  Chit - Chat  /  QUICK! Need help! PERL programmers!
Posted by: tylermenezes, January 27, 2007, 12:06am
Okay Justin, could you please help me here. Your E-Blah expertise would be of GREAT help...

I'm designing a PERL script for my school's library and I need to have it done by Monday, Jan. 29, 2007! My school's library has what they call "library passes" because everyone at my school hangs out in the library during lunch and plays video games on the computers. People can get a pass in the morning for that day, or can ask a librarian for a pass for the entire quarter.

What I need your help with is creating the member system. The one in E-Blah is great, so maybe you can help here? What I need to do:


I already have the console, login, and request pass features done, but there's no way for the librarians to issue passes, because I have no idea how to store names, quarter pass (boolean), and valid date (if quarter pass is false).

Again, PLEASE help. I need this by Monday, because that's the start of the new quarter, and they said if I could get it done by then they'd love to use it. I'm reading a book I bought on PERL, but I'll never finish it in time, and I know VERY little about the language. I don't have any money to donate right now, but if you help I'll donate as soon as I get some.


Thanks so much! If you need a copy of the existing code, it's attached.
Posted by: Justin, January 27, 2007, 1:42am; Reply: 1
You want a full scaled member back end in a few days?  Ouch.  It's not that hard, but if you don't know much perl it will be.

I'd try to do it with XML myself.  Just do it that way.  I'm not sure how you'd do the other stuff, it's something you'd have to actually plan out.  You'll want to get the current time, probably, and add X amount of days to it to state how long it's valid for (then the code blocks it if it goes over those dates, etc).
Posted by: tylermenezes, January 27, 2007, 1:49am; Reply: 2
I just really need some way of having PERL process a file with user information in it like:

\n - new person
| - seporator

something like that, I could probably do the processing code, but I have no idea how to get the processing into arrays. If you could give me some example code to seperate:

username|quarter(1/0)|dateissued|lunch(1/2/3)

into arrays named "username", "quarter", "dateissued", and "lunch" then I could do the rest. I already figured out to do date arrhythmic and revoking of passes.

If XML would be easier, let me know. Keep in mind that if it requires an additional Perl module, my website server host won't install it. I kind of like the way E-Blah does it though. Everything I need is there in the Eblah code somewhere... Member deletions, date registered, ranks, etc. if you could even give me some guidance as to how you did this for E-Blah, that would be really helpful.

Thanks!


Thanks for the help!
Posted by: Justin, January 27, 2007, 12:03pm; Reply: 3
($username,$quarter,$dateisued,$lunch) = split(/\|/,$string);

Just do a for each and then you'll have your variables.
Posted by: tylermenezes, January 27, 2007, 3:47pm; Reply: 4
Thanks you so much!

How could I load a specific member though? i.e.

Tyler|1||2
Justin|0|January 27 2007|1

and someone is looking for a member named Tyler so I look for a line starting with Tyler?


Thanks again, again!
Posted by: Justin, January 27, 2007, 4:06pm; Reply: 5
foreach(@line) { ... }
Posted by: tylermenezes, January 27, 2007, 5:19pm; Reply: 6
So that will look for each new line in the file?

My code should look like:

open(FH3,"./libpass/list.txt");
$memberdb = <FH3>;
close (FH3);
foreach(@line) {
($username,$quarter,$dateisued,$lunch) = split(/\|/,$memberdb);
print "Name: $username<br />Quarter: $quarter<br />Date: $date<br />Lunch: $lunch<p />"
}

And that would give me

Name: Tyler
Quarter: 3
Date:
Lunch: 2

Name: Justin
Quarter:
Date: January 27 2007
Lunch: 1


Is this correct?

Thanks again, again, again!
Posted by: Justin, January 27, 2007, 5:23pm; Reply: 7
More like this ...

Code
open(FH3,"./libpass/list.txt");
@memberdb = <FH3>;
close (FH3);
chomp @memberdb;
foreach $arraystring (@memberdb) {
($username,$quarter,$dateisued,$lunch) = split(/\|/,$arraystring);
print "Name: $username<br />Quarter: $quarter<br />Date: $date<br />Lunch: $lunch<p />"
}
Posted by: tylermenezes, January 27, 2007, 5:52pm; Reply: 8
THANK YOU SO MUCH!!!

One final queston: How can I use something (probably regex) to only return members with lunch 3, or name "Tyler"?

If you want to see what I'm working on: http://www.programsandwebsites.com/libpass/index.pl?action=login&login=grizzlies
Posted by: Justin, January 27, 2007, 6:07pm; Reply: 9
Umm, just do the foreach and then do:

if($line =~ /\QTyler\E/sig) { ... }
Posted by: tylermenezes, January 27, 2007, 6:10pm; Reply: 10
Thanks! You rock!

Line should be $arraystring though, right?


I actually do have one queston, what could I use to delete a member's line, assuming I know the member's full name ($username)?
Posted by: Justin, January 27, 2007, 6:14pm; Reply: 11
Just add the old stuff, minus the old username, into an array, then write it to file.  Or write it to file and don't stick it into an array, which is faster.
Posted by: tylermenezes, January 27, 2007, 7:43pm; Reply: 12
How could I do that? I'm new to PERL remember, I know the print method, how to set cookies, use lines, and if lines, but that's it.
Posted by: Justin, January 27, 2007, 8:16pm; Reply: 13
A loop that gets rid of the stuff you don't want.  Use next; ...
Posted by: tylermenezes, January 27, 2007, 9:03pm; Reply: 14
Ok, here's what I've got:

Code
sub deleteuser{
my $td = shift;

	$openpg = "$dir/list.txt";
open(FH3,"$openpg");
@memberdb = <FH3>;
close (FH3);


chomp @memberdb;
foreach $arraystring (@memberdb) {	
($username,$quarter,$dateisued,$lunch) = split(/\|/,$arraystring);
push(@usernames, $username);
push(@quarters, $quarter);
push(@dateissueds, $dateisued);
push(@lunches, $lunch);
}
$count = 0;
foreach $user (@usernames) {
	if($user eq $td){
	delete @usernames[$count];
	delete @quarters[$count];
	delete @dateissueds[$count];
	delete @lunches[$count];	
	$count--;
	}
$count++;
}
$c2 = "0";
foreach $user (@usernames){
if($ct eq "0"){
$user = "\n$user";
}
$openpg = "$dir/list.txt";
open(FH4,">$openpg");
print FH4 "$user|$quarters[$ct]|@dateissueds[$ct]|@lunches[$ct]";
close (FH4);
print "$user|$quarters[$ct]|@dateissueds[$ct]|@lunches[$ct]<br>";
$c2++;
}

}


This works, but it has a few strange problems. If I try to delete "Joe Smith" and there's also a user named "John Smith", they're both deleted. Could you tell me what I'm doing wrong?
Posted by: Justin, January 27, 2007, 9:31pm; Reply: 15
I wouldn't delete the array variables like that ...
Posted by: tylermenezes, January 27, 2007, 9:35pm; Reply: 16
It works though. The only relievent part is:

Code
chomp @memberdb;
foreach $arraystring (@memberdb) {	
($username,$quarter,$dateisued,$lunch) = split(/\|/,$arraystring);
push(@usernames, $username);
push(@quarters, $quarter);
push(@dateissueds, $dateisued);
push(@lunches, $lunch);
}
$count = 0;
foreach $user (@usernames) {
	if($user eq $td){
	delete @usernames[$count];
	delete @quarters[$count];
	delete @dateissueds[$count];
	delete @lunches[$count];	
	$count--;
	}
$count++;
}


And all I need help on is "if($user eq $td){". I don't really care about speed, I just need to know why this deletes both "John Smith" and "Jane Smith" and "John Doe". Could you help me, or suggest a better way of going about this? This is the last feature to fall into place, and then I can release it.
Posted by: Justin, January 27, 2007, 11:35pm; Reply: 17
I don't really see what you're doing.

Code
open(SOMEFILE,"file.txt");
foreach $arraystring (@memberdb) {	
	($username,$quarter,$dateisued,$lunch) = split(/\|/,$arraystring);
	if($username eq 'someuser') { next; }
	push(@usernames, $username);
	push(@quarters, $quarter);
	push(@dateissueds, $dateisued);
	push(@lunches, $lunch);
	print SOMEFILE "$username|$quarter|$dateisued|$lunch\n";
}
close(SOMEFILE);


It's not near as hard as your delete thing is making it ...
Posted by: tylermenezes, January 27, 2007, 11:39pm; Reply: 18
How do I do it then? I need to: delete a line belonging to a member I know: The username

Remember, this is stored in a file in the format mentioned previously.
Posted by: Justin, January 27, 2007, 11:45pm; Reply: 19
I just showed you how.  Make sure you do > before the filename, though.  You want to rewrite the file, not read it.
Posted by: tylermenezes, January 27, 2007, 11:48pm; Reply: 20
oh, sorry. thouht you were quoting my code  :B
Posted by: tylermenezes, January 27, 2007, 11:59pm; Reply: 21
Thanks for all the help here. In the unlikly (:P) event I could help you in any way, just let me know.

It works, fully!
Print page generated: February 12, 2012, 1:40pm