Loathe as I am to disagree with such as these, I must do so now. IMHO, Internet calculators are a great application for cookies.

When I put something in the memory of my calculator on my desk, it is not a system-generated price, or secret, or whatever, but just a number I already typed in once and don't want to type in again (at least for the next few hours/days). I don't expect this memory to last forever, or get put in a database, or follow me to the calculator at home, I just want it to be there when I show up tomorrow morning without having to leave my browser on all night.

It looks like what you are doing is just storing values already entered by the user so they don't have to type them in again. You don't care if the user edits the cookie, or if the values follow her to a different computer.

Here is the code snippet I wrote for a type of internet calculator that uses a similar kluge to yours. A 2-D array of atoms with upper and lower limits is stored in a string using a space to delimit in one dimension and a . to delimit in the other dimension. The calculator will determine all molecular formulas containing these elements within these limits that have a given exact mass. The data can be slow to enter and successive forms will only require slight changes to the input data, so it will be kept in a cookie for 3 days so I can leave for the night without having to re-enter the array in the morning.

if(param()){$cookval=param('entercook');} elsif(cookie('testcook')){$cookval=cookie('testcook');} else{$cookval="O 0 10.N 0 20.C 1 40.H 1 100";} $cookie = cookie(-name=>'testcook', -value=>$cookval, -expires=>'+3h');

In case you're interested, this will test to see if the form has been submitted with new input data, failing that it will check for the data in a cookie, and failing that will set the cookie to a default value.

I still haven't answered your question, but perhaps one of our more enlightened bretheren can shed some light on the matter (is storable the best way?).

drinkd


In reply to Re: Storing an array in a cookie... by drinkd
in thread Storing an array in a cookie... by Nacho37

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.