On Tuesday, February 11, 2003, at 10:56  AM, Garrett Goebel wrote:
What about this?

      \@array
hmm. As perl Apoc2, Lists, RFC 175... arrays and hashes return a reference
to themselves in scalar context... I'm not sure what context '\' puts them
in.

I'd guess \@array is a reference to an array reference.
I understand the logic, but:

my $r = @a; # ref to @a
my $r = \@a; # ref to ref to @a ???
my @array = (\@a,\@b,\@c); # array of three arrayrefs

Boy howdy, I think that would freak people. But making '\' put them in list context would of course be far worse:

@array = (\@a); # means @a = ( \@a[0], \@a[1], ... ) ???

So I think '\' just puts things in C<Ref> context, which solves the problem and always does The Right Thing, I think. So the context rules for arrays are:

- in scalar numeric context, returns num of elements
- in scalar string context, returns join of elements
- in scalar ref context, returns a ref
- in generic scalar context, returns a ref

IMO.

MikeL

Reply via email to