Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
OK - maybe my first guess was wrong... :)

If I use "my $t" within this sub and localise it, we wont be referring to the first $t defined outside the sub.Is that right?
Yes - that's right. I thought maybe you were using $t for some other purpose, but it would appear not.

I'm not sure where we should use "my", and where we should not
Check out the section on 'scope' in whatever perl books/docs you have. 'my' declares a variable within the 'current scope' - if that's in a sub (or any pair of braces),it's gone when you exit the sub. If, on the other hand, it's in the 'main body' of your code, it's global oops - I mean file scoped...ermm..global to your file...ermm...you know what I mean - see the AM posting below... . That is generally a Bad Thing.

Turning on use strict gives no message about $t.
Does it give messages about other things? What about use warnings? Fix these, and your problem may possibly go away.

I haven't any more specific ideas, but here are a few general suggestions.

  • use strict; use warnings;
  • Don't use globals if you can help it. Pass arguments to subroutines instead - this helps your code become more 'general'
  • use strict; use warnings;
  • Refactor and tidy up. sub replace1,sub replace2 etc. look like they should be candidates for a single sub, with the replace string (and probably the text widget as well) passed in as a parameter.
  • use strict; use warnings;
  • Debug. Lots. Print out the values of $t after you initialise it, before you use it, after you use it etc. Check they're all the same type/memory address.
Hope this helps, Ben.

In reply to Re: Re: Re: Tk question by benn
in thread Tk 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (8)
    As of 2020-07-06 20:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?