[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Constants as array refs



On Thu, Mar 23, 2000 at 03:17:42PM -0500, John Porter wrote:
> Jeff Boes wrote:
> > 
> >   use constant CARRAY => [1, 2, 3, 4];
> > 
> > What is the syntax to dereference this constant directly into the list of a
> > 'foreach' loop?
> 
> It is (very unfortunately) necessary to remember that constants
> defined with "use constant" are actually subroutines.
> 
> 	for ( @{ &CARRAY } ) { ...

Using the & syntax prevents Perl from optimizing calls to constant
subroutines.  Doesn't make a difference in this case, because CARRAY
returns an anonymous array rather than a scalar constant, but in general
its preferable to use + or () to disambiguate subroutine calls from
barewords.

Ronald


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe