Oh, good lord. I have a problem and a half, I think.

I'm building a cart system for a fairly unique situation. The whole list of products has barebones searchability and needs to update constantly - that is, some of them are unique, some we only have five of, etc. - and as a result I came up with what I hoped was a dandy way to handle the carts.

"If one program dealt with all the cart/product stuff, then it would just have to keep updating the return page's stuff."

Ideal behavior for this program is as follows:

Customer comes to the site and locates a card they like. They click "Put In Cart" next to it.

When they click the submit button, the program checks first if they have a cart. If they don't, it generates a random, 8-digit number for a cart name and gives a hidden tag that name so it can be accessed next time.

Once they've got a cart, it "drops" it in, decrementing the stock file by one of those things and incrementing their cart file by one of those things. It only has to append it; it'll get sorted when it's viewed.

Then it closes the cart, closes the stock file, and checks if there was a search term. If there was, it returns the page for that search term.

I believe that this will produce a faster drop-find-drop-find cycle, because you can click on three cards, put a new search term for the other cards you want, and go to the new page while you drop the ones you want in your cart. You don't have to, though. And you can check your cart at any time.

The problem is the generator. I'm having trouble with this, so it's really just a yes-or-no question, because I've been banging my head against it for a few days, trying to get it right.

Is it *possible* to open a filehandle with a variable name for a filename? That is, will open(CART, "$cartname") open the value of $cartname? Or will it try to open a file called '$cartname'?

Should I store the cart name - or even all the data that would go into the cart itself - as a cookie, or as several? I realize that not all browsers support them, unreliable, etc., so I didn't want to try it, but if it's a better idea I'll give it a shot.

Is this way of dealing with it utterly senseless? I realize there may be a security issue with this ("...hey, every time I do that it generates a new file! I wonder how many files I can get it to make on their server...") but I figure that when it's a problem, I'll have figured out how to handle it.

I know, I'm terribly amateurish at this...but that is why I'm seeking wisdom.


In reply to Crumbling Cookies, Passed Page Values, and File Handling by chaoticset

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.