On Aug 15,  3:16pm, Russ Allbery wrote:
> Wholeheartedly agreed.  If something is an array, it should start with @.
> If we're adding language changes that introduce arrays that don't start
> with @, that's the mistake.

Agreed, but with a slight change of perspective.  I don't think it's
so important that a variable that _holds_ a list be prefixed with a '@'.
What's more important is that when you _use_ a variable, you prefix it with
a '@' to indicate the expected return type.  At that point, Perl can DWIM
or FOAD accordingly.

e.g.
  $foo = [ 1, 2, 3 ];    # it's a list (ref), but starts with a '$'
  @bar = @$foo;          # but now we "cast" (deref) it to look like a list

The confusion comes (IMHO) in having to add funny characters together,
or doing funky "casting" to make the right kind of value come from the
right kind of variable.

  @$foo;         # '$foo' is the list, dereferenced to a list '@'
  $foo{bar}      # '%foo' is the hash, accessed to return a scalar '$'
  @foo{bar,baz}  # '%foo' is the hash, sliced to return a list '@'
  @$foo{bar,baz} # '$foo' is a hashref, sliced to return a list '@'

You get these weird situations where you're accessing a variable as
'@something' but it's actually coming from '%something'.  Hence the
Highlander Variables RFC which should hopefully do away with
much of this confusion.


A

-- 
Andy Wardley <[EMAIL PROTECTED]>   Signature regenerating.  Please remain seated.
     <[EMAIL PROTECTED]>   For a good time: http://www.kfs.org/~abw/

Reply via email to