From perldoc perlsub, section: Temporary Values via local()

A `local' modifies its listed variables to be "local" to the enclosing block, `eval', or `do FILE' --
and to any subroutine called from within that block.

But knowing this is not enough, you have to think about the implications as well!

Recently I had a hard time to find a bug in a Tk application.

Part of the application scans large textfiles. If a certain string is found, it is inserted into a listbox.
During that scan, you should be able to use the application in a normal way.
This is easyly achieved, you just have to do a $MW->update() frequently and all Tk events will be processed.

So far no problem.
But when you change the input line separator $/ to something really weird for those scan, you've got a PROBLEM!
Even if you do it local!

Because local means local to the block and all called subroutines, of which $MW->update() is one, and all subs called during the event processing also.
So every reading from files done somewhere in the application went gaagaa during those scans.

I spent hours!


In reply to Fun with local :-( by busunsl

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.