On 23 Jun 2006 at 12:41, [EMAIL PROTECTED] wrote:
> In a message dated 6/23/2006 12:30:35 P.M. Eastern Standard Time,
> [EMAIL PROTECTED] writes:
>
> > hi charles --
> >
> > In a message dated 6/22/2006 10:38:47 P.M. Eastern Standard Time,
> [EMAIL PROTECTED] writes:
> >
> > > BEGIN {
> > >
> > > my @pad = (some large list of numbers);
> > >
> > > ...
> >
> >
> > just a point of curiosity...
> > why is @pad defined inside a BEGIN block instead of just any old
> block?
> a little more reflection is sometimes useful.
> the answer, correct me if i'm wrong, is that placing @pad in a BEGIN
> block closure
> allows one to be sure that the array will be initialized before any of
> the functions that
> depend upon it are run, whereas if it was in an ordinary block closure
> one could not
> be so assured.
But I'm still not understanding: the *SCOPE* of that declaration should
be limited to the BEGIN block, and so if you try to *use* "@a" anyplace
else you should get an error. In addition to the fact that it is [IMO]
unnecessarily obscure code, since if that worked as you said, then it'd
be quite the exception to the entire block-structuring/scoping rules.
I tried a test case:
perl -e 'BEGIN { my @a = (4); } ; warn "@a" '
Warning: something's wrong at -e line 1.
Which is just what I would have expected to have happened. When I change
that code to what I think is the more clear version:
perl -e 'my @a; BEGIN { @a = (4); } ; warn "@a" '
4 at -e line 1.
it is not only more clear [making the declaration and scope of @a crystal
clear AND making its initialization clear] but it works. so I must be
missing something: did the original code [with the 'my' inside the BEGIN]
actually *work*??
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
mailto:[EMAIL PROTECTED] Pearisburg, VA
--> Too many people, too few sheep <--
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs