在 2006/8/18 上午 3:31 時,Ben Morrow 寫到:
Just to make sure I've got all this straight:

    =:= compares names
    === compares containers
    eqv compares values

=:= evaluates both sides as lvalue -- that's VAR() -- and compare them with ===. === evaluates both sides as rvalue and, for container (mutable) types, compares their pointer address. eqv evaluates both sides as rvalue and, for container (mutable) types, compares their content values.

None of the three coerces their arguments to concatenated List (aka list flattening, aka slurpy context).

So given an array @W,

    my @X := @W;            # @X =:= @W
    my @Y =  @W;            # @Y === @W but @Y !=:= @W
    my @Z =  @W.clone;      # @Z eqv @W but @Z !=== @W

Your Array example would be correct with the $ sigil:

    my $w = [1,2,3,4]; # Scalar containing Array
    my $x := $w;       # $x =:= $w
    my $y =  $w;       # $y === $w but $y !=:= $w
    my $z =  $w.clone; # $z eqv $w but $z !=== $w

However, &infix:<=> when its left-hand side is an array, has an different signature (and indeed, different precedence) than when its left-hand side is a scalar:

    my $y = $w;       # does not flatten $w
    my @Y = @W;       # does flatten @w, essentially doing a .clone
    my @Z = @W.clone; # same as "my @Z = @W" really.

So the two assignments (@Y and @Z) above turns out to be the same thing, and neither
will make "===" hold afterwards.

Cheers,
Audrey

Attachment: PGP.sig
Description: This is a digitally signed message part

Reply via email to