note
benn
OK - maybe my first guess was wrong... :)
<p><i>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?</i>
<br>Yes - that's right. I thought maybe you were using $t for some other purpose, but it would appear not.
<p><i>I'm not sure where we should use "my", and where we should not</i>
<br>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 <strike>global</strike> <small>oops - I mean file scoped...ermm..global to your file...ermm...you know what I mean - see the AM posting below...</small> . That is generally a Bad Thing.
<p><i>Turning on use strict gives no message about $t.</i>
<br>Does it give messages about other things? What about <code>use warnings</code>? Fix these, and your problem may possibly go away.
<p>I haven't any more specific ideas, but here are a few general suggestions.
<ul><li><code>use strict; use warnings;</code></li>
<li>Don't use globals if you can help it. Pass arguments to subroutines instead - this helps your code become more 'general'</li>
<li><code>use strict; use warnings;</code></li>
<li>Refactor and tidy up. <code>sub replace1</code>,<code>sub replace2</code> 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.</li>
<li><code>use strict; use warnings;</code></li>
<li>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.</li></ul>
Hope this helps, Ben.
289743
290315