On Fri, Jun 07, 2002 at 05:30:17PM -0700, Bryan R Harris wrote:
> 
> Quick question:
> 
> When exactly are {} braces required?  I notice when following references,
> $ { $var } and $$var both work identically.  Do you ever actually need
> them?

I'm assuming you meant in the context of dereferencing only.  Braces aren't
really required, unless you want Perl to do what you want it to.  :)

The braces serve to disambiguate what you're dereferencing.  No, braces are
not required with $$var, because there is only one way that can be read. 
Braces are required when trying to dereference, for example, an array
element:

    @foo = (\1, \2, \3);
    print ${ $foo[0] };

If you omitted the braces:

    $$foo[0]

You'd effectively be saying "retrieve the 0th element of the array reference
$foo", instead of what you meant "retrieve the 0th element of @foo and
dereference it".  This may be a perfectly legitimate action, except that's
not what you intended.

I can't really put it in terms of a hard and fast rule.  Perhaps another on
this list can.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to