Pug has asked for the wisdom of the Perl Monks concerning the following question:
I have a question concerning Perl's closures.
--
Pug
The code below should, to me, completely work.
But when I call doesnt_work @r is not initilized. 8(
Which is surpising to me because perl knows that sub doesnt_work exists
so why doesn't it init @r when it is called?
#!/usr/bin/perl -w { my @s=("This works\n"); sub works { shift @s} } #This works.. print &works; # Error!! # This gives an error of Use of uninitialized value in print at .... print &doesnt_work; { my @r=("Should this work..\n"); sub doesnt_work{ pop @r; } }
--
Pug
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Closure question
by broquaint (Abbot) on Mar 02, 2004 at 17:44 UTC | |
Re: Closure question
by Limbic~Region (Chancellor) on Mar 02, 2004 at 18:05 UTC | |
Re: Closure question
by fletcher_the_dog (Friar) on Mar 02, 2004 at 18:05 UTC |
Back to
Seekers of Perl Wisdom