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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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



Jan 24, 2001, 8:30 AM

Post #1 of 4 (577 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.


Jan 24, 2001, 1:04 PM

Post #2 of 4 (572 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.


Jan 24, 2001, 4:13 PM

Post #3 of 4 (569 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:

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


Jan 24, 2001, 8:38 PM

Post #4 of 4 (566 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:


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