Incrementing the receipt number is supposed to be something that happens when a receipt is created and stored. Printing a record really has nothing to do with creating a new record, so incrementing to the next record number should not be part of the print function.

If you are keeping track of receipt numbers together with associated data in a text file, I would assume that this is not a "write-only" file. Does your Perl/Tk app also provide a means of reading back from the file?

If so, then you should make the access to that file "modular": create a separate module for i/o on that file, so that you have a clean, simple set of methods to create a new record, fetch back the last record, determine the next available receipt number, and search for an arbitrary receipt (by number or by other data content).

Or maybe you'd rather use some sort of database instead, or at least a DBM file tied to a hash in your script (check out AnyDBM_File), using the receipt number as the key value in the hash or receipt table.

But the main thing is: write your code so that the receipt number is only incremented as part of creating a new record, not as part of printing anything.


In reply to Re: Perl Tk variable update question by graff
in thread Perl Tk variable update question by perl_seeker

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.