Jeff 'japhy' Pinyan wrote:
>On Jan 28, Jan Eden said:
>
>>sub read_index {
>>my $gedicht_path = shift; my (%author_indexlines, %author_headlines,
>>%gedicht_lines, @author_letters, @gedicht_letters, @alphabet_index);
>>find (\&read_poem, $gedicht_path); print %author_indexlines; #
>>nothing is printed out here!
>
>The only way that hash can get populated outside of this function is
>if it you pass it by reference to another function, and populate it
>THERE. A my() variable is scoped lexically -- that is, physically.
>It only exists here, inside this block of code, unless you send its
>reference to another scope.
>
Yes, that's what I suspected. But I was tricked because ...
>
>You're not filling the same hashes and arrays; you're filling GLOBAL
>hashes and arrays that happen to have the same name. If you were
>using 'strict', you'd be told about that.
>
... I *did* use strict in my main script. I did not within the module the subs reside
in, though. Since the main script never saw the subroutines, its strict pragma did not
notice my error. Doh!
>>Can anyone point me to the (probably obvious) problem with the
>>locally scoped variables?
>
>One way you can fix your situation is to use a closure -- an
>anonymous code block created inside read_index():
>
Thank you! I will try this as soon as possible.
Learning more and more,
Jan
--
How many Microsoft engineers does it take to screw in a lightbulb? None. They just
redefine "dark" as the new standard.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>