Thanks guys! I did not think that it was possible, but some Perl guru might be able to prove me wrong. I just did not want to pass references into the subs, as a) I have nested loops, with nested subs b) Looking for an easy way to do it. c) growing my meager Perl skillz.
So I have: ----------- global hash of hashes of hashes ## iterate throught the hash lists and do stuff... loop1 loop2 loop3 call sub 1 which calls sub 2 which wants to set the global variable (!!!) but needs to know where in loop1, 2 and 3 it is being called from! ------------ If I hafta pass in refs from loop1 2 and 3 all the way down the line, So Be It. It just makes my argument list a little unsightly, is all. "Bob Showalter" <[EMAIL PROTECTED]> wrote in message 2E4528861499D41199D200A0C9B15BC001D7E734@FRISTX">news:2E4528861499D41199D200A0C9B15BC001D7E734@FRISTX... > Bob Showalter wrote: > > ... > > But foreach loops are funny. Try this: > > > > use strict; > > > > our $x = "Hello"; > > Aargh! That should be "my". To much confusion in my cutting/pasting. > > > > > printx(); > > for $x (1..3) { > > print "$x\n"; > > printx(); > > } > > printx(); > > > > sub printx { print "$x\n"; } > > > > prints: > > Hello > > Hello > > Hello > > Hello > > Hello > > > > Hmm, now try it with "our": > > > > use strict; > > > > our $x = "Hello"; > > This "our" is correct. > > > > > printx(); > > for $x (1..3) { > > printx(); > > } > > printx(); > > > > sub printx { print "$x\n"; } > > > > prints: > > Hello > > 1 > > 2 > > 3 > > Hello > > > > The loop variable can either be a global (default) or a lexical > > scoped to the loop. It can't reuse a lexical in an outer scope. Also, > > when a global is used, it is localized to the loop. > > > > So, the OP's problem can be addressed by: > > > > 1. Using the global variable. > > > > 2. Passing the variable to the function. > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]