ti-source has asked for the wisdom of the Perl Monks concerning the following question:

I work at our local GIS department, working on maps, and that kind of stuff. I recently added a database search to their website, which I recently redesigned (the website). The script behaves fine sometimes, but not other times. The script uses the DBD::Xbase module by Pratap Pereira, which works just fine (except it wouldn't work with 'use strict'). I'm not a hardcore perl professional, but I do the best I an. The script runs on a Novell NetWare 5.1 server with Novell's perl NLM. On some occasions, the perl NLM will hog over 50% of the server's resources (or the NLM will crash). The network admin, who is not in the GIS dept, is threatening to cut all my ties to perl because he says it hurts efficiency of his server. He says its not the server, but my fault. Anyway, here's the script. It reads a dbf file that I cannot post for legal reasons. I'd appreciate it if anyone can tell me if I have a major script problem or if its just NetWare. The extra comments were for my fellow employees, so they can understand the script. Thanks.

Get it here: http://www.emerycounty.com/gis/mapdata/searchdb.txt.

Replies are listed 'Best First'.
Re: Novell NetWare perl reading DBF's.
by chromatic (Archbishop) on Nov 29, 2000 at 09:47 UTC
    Does XBase have any built in searching or indexing? I'm not familiar with it, so I don't know.

    If so, I would definitely prepare a query in Perl and let the database handle it. It ought to be optimized for that sort of thing.

    Regardless, there are a few places where you have things inside a loop that don't seem to need to be there. Case in point, checking the query for a certain type, then choosing which keywords to find. Unless the query changes in the middle of the search, you can compute the search elements just once, not once for each row of the database.

Re: Novell NetWare perl reading DBF's.
by cephas (Pilgrim) on Nov 29, 2000 at 05:51 UTC
    Have you tried narrowing down the cases that make the script run wild? Are they always the same queries, or is there no apparent pattern to it?

    As far as your code goes, there are several things I feel I should point out.

    For starters, you should use: use lib '/Xbase'; instead of your BEGIN block.

    Another thing is, why are you using Socket.pm? Maybe I missed something, but I didn't see anything that needed that module

    Next off you should be using CGI.pm instead of parsing out form input yourself.

    Also, you use /gis on a lot of your matches on a variables, but not sure why. In most cases it seems that matching once would be fine (in an if statement), thus no need for /g, /s if I recall properly (regex gurus correct me if I'm mistaken), makes '.' match a newline (so unless you've got real regex stuff inside those variables, this is probably not what you want.) Which brings to the next thing, your trusting the input to be valid and good (which is really a whole different discussion), at the vary least, to make the regex's work more like expected (again unless you're doing something strange elsewhere that I'm not aware of), you should probably use quotemeta on the variables that you are using as your match pattern.

    I'm not really familiar with Xbase or Novell, so I can't tell you what problems you may or may not be having there, but there seems to be a lot of code to clean up no matter where the exact problem lies.

    cephas
Re: Novell NetWare perl reading DBF's.
by ti-source (Novice) on Nov 29, 2000 at 20:47 UTC
    The module doesn't have searching capabilities -- only read capabilities. I know CGI.pm will do that stuff for me, but I like doing it myself (maybe I'm wierd). The queries don't seem to affect how the script runs (it seems random). Maybe the regexp's could be set up different; I'm not a hardcore perl programmer. If it works, I'm happy. If it doesn't, I try to fix it.

    I can't remember why socket.pm is in there. I'm sure there was a good reason for it; it's been too long.