CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
String searching/matching

 



Turco
Deleted

Jan 24, 2001, 8:30 AM

Post #1 of 4 (552 views)
String searching/matching Can't Post

I am making a small cgi script that will search a data file, take out all lines that do not contain any instances of two different strings, and put those lines into an array. This is the part that I seem to be having problems with, because it is only removing the line containing the second string, not the first:

open (USRDAT, "udata");
while (<USRDAT>) {
@line = <USRDAT> unless /$usrinfo[0]|$destinfo[0]/;
}
close (USRDAT);

both usrinfo and destinfo are arrays that already have the correct values in them at this part of the program, I checked that, but it is still not removing the line containing $usrinfo[0]. If anyone could help me out, I'd really appreciate it.



modified
Deleted

Jan 24, 2001, 1:04 PM

Post #2 of 4 (547 views)
Re: String searching/matching [In reply to] Can't Post

@line = <USRDAT> unless ($_ =~ /$usrinfo[0]/ || $_ =~ /$destinfo[0]/);

Try that in place. It's just my guess. I don't have much idea as to what you're trying to do here.



japhy
Enthusiast

Jan 24, 2001, 4:13 PM

Post #3 of 4 (544 views)
Re: String searching/matching [In reply to] Can't Post

I'm not totally sure I understand what you're doing... you're not modifying a file anywhere. Perhaps you mean to do something like this:


Code
{ 
local $^I = '.bak'; # to keep a backup
local @ARGV = "udata"; # the file to modify
while (<>) {
print if
index($_, $usrinfo[0]) == -1and
index($_, $destinfo[0]) == -1;
}
}

Perl can do in-place file editing for you -- it takes care of ALL the magic for you.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


Turco
Deleted

Jan 24, 2001, 8:38 PM

Post #4 of 4 (541 views)
Re: String searching/matching [In reply to] Can't Post

I've attached the entire script this time, its part of a game that I'm making for a friend, to let the players log in to this page and transfer their money, etc. This is the money transfer part. Any help on getting this to work would be very appreciated. This is what the original data file, udata, looks like:

joe;jowe@bobi.com;pass;HRR;Mercenary;9999;4;1;999999;na;2
simon;s@ob.com;pass;DCM;House;1222;1;2;999999;na;-1
templis;t@t.com;pass;comstar;Admin;999999;1;1;999999;admin;-1
bob;bob@bob.com;pass;WD;Mercenary;9999;4;1;999999;na;2
matt;matt@obob.com;pass;GDL;Mercenary;1255;4;1;999999;na;3

and the program should take one credit from matt, and give it to joe, which it does, but it leaves the unmodified data for 'matt' in the file, as well as the new stuff. Try it yourself, just copy the above out and paste it in a file named udata. Sorry for being so vague before, but I was trying to keep it simple :) O well, thanks for any help in advance


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives