chaoticset has asked for the wisdom of the Perl Monks concerning the following question:

This is for my ongoing project: A cart program to sell Mag*c singles for a game shop site.

Normal carts order things that are constantly renewed; this one orders things that there are limited supplies of, sometimes only one of. However, there are literally going to be *thousands* of cards in the stock.

The behavior of the cart is supposed to be thus:

Click on the 'singles' link. The initial page comes up, with just a search box and a little explanation, which says to put the first few letters of the name of the single you want.

If you don't, it comes back to that page. If you enter at least one letter, it takes a rather large hash, and for *every value with those first few letters*, will print that entry's information.

I did this with this:

$firstfewletters = param("SEARCH"); #a text box elsewhere if ($firstfewletters) { #checks that $firstfewletters has value ***start table here*** foreach $card (@stock) { #for every card in stock... if ($card =~ m/^$firstfewletters/) { # ...if that card's first few letters match # $firstfewletters ***printing each table element here*** } } ***end table here*** } else { print "Please enter the first few letters of the card's name, or ent +er a single letter to view just the cards beginning with that letter in our singles coll +ection."; }
Now, the fun part is what it does.

The first time it works; the box, the button, the explanation.

Every time after, it just prints the table with the table header, as if no cards matched.

I thought I'd figured out how to use regexes right, but it appears I'm missing something.

Apologies in advance if this is (stupid|pointless).

Edit kudra, 2001-10-22 Code tags

Replies are listed 'Best First'.
Re: CGI Values, Debugging, And Dynamic Pages
by traveler (Parson) on Oct 22, 2001 at 01:10 UTC
    It may not be a regex problem. It may be a problem with how your script is invoked.or something like caching Is it a CGI, is it mod-perl, is it some other method? Try printing out to a disk file on the server (I assume you are using a web server and a browser client) to see if the data are even being generated. Also print out the first few letters: the query.

    I've had similar problems on IE under NT4. In my case it seemed to be related to caching, but the problem went away after some other seemingly unrelated changes to the page so I didn't pursue it.

    If the query is succeeding, I'd check that I had turned off caching at the client, and made sure I closed the connection to the client so it would finish displaying the data (necessary in one or more popular browsers...). If it is a client caching problem, there are solutions and I'm pretty sure you can find a link to one on merlyn's page.

    HTH, --traveler