Hello:

The logic flow in my program goes this way
my $mw = MainWindow->new; $mw->geometry("500x250"); /*Other stuff*/ $mw->Button(-text=>'OK',-background=>'blue',-command=>\&ok_but)->pack( +-side=>'top',-pady=>2); MainLoop; sub ok_but { $receiptno=40; /*Other stuff*/ $sw->Button(-text=>'Deposit work receipt',-background=>'blue',-command +=>\&deposit)->pack(-side=>'top',-pady=>2); sub deposit{ my $dw = MainWindow->w; $dw->geometry("500x700"); /* Entry boxes and lists where user enters/selects data for receipt generation */ $dw->Button(-text=>'Print receipt',-background=>'blue',- command=>\&d +eposit_fwrite_print)->pack(-side=>'top',-pady=>2); } sub deposit_fwrite_print{ /* Write data to text file and print recipt receipt using Win32::Printer::Direct; */ $receiptno=$receiptno +1; } } End of subroutine ok_but
The user clicks on the 'Print receipt' button and receipt gets printed. But suppose the user wants to print the receipt again and clicks on the button in the same open window a second time, the $receiptno gets updated and the receipt number for the same set of data is printed incorrectly (number +1).Also the same set of data is written to the text file again.

How to ensure that $receiptno is updated and data is written to text file only if a new set of data is entered by the user?

Also once u exit the program the value of $receiptno gets lost.How do we ensure that each time the program is invoked $receiptno is set to last value used + 1?

I have thought of solutions to all the above but was wondering if someone could suggest something more efficient?

Thanks for reading,
perl_seeker

In reply to 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.