David Storrs wrote:
Urk. I, for one, will definitely find this surprising.  I would have
expected:

x = <whatever>; $y = 1; z = 2 3

to obtain what you have expected, you need to explicitly treat the array as a list of values with the unary splat:


    foo($x, [EMAIL PROTECTED]);

But I suppose it's all a question of learning to love the Brave New
World in which arrays are actually objects (sort of).

more to the point, arrays are automagically referenced in scalar context:

    @a = @b;  # same as perl5
    $a = @b;  # means $a = [EMAIL PROTECTED] in perl5
    $a = [EMAIL PROTECTED]; # means $a = @b in perl5 (more or less)

another thing that may surprise you (it still surprises me, somehow):

    sub bar($x, $y, $z) { ... }
          # ^ note x is scalar here!

    my @coords = (1.0, 3.0, 5.0);
    bar(@coords); # wrong
                  # x => [EMAIL PROTECTED], y => undef, z => undef

    bar([EMAIL PROTECTED]); # ok

but then, you could define:

    multi sub bar($x, $y, $z) { ... }
    multi sub bar(@coords is shape(3)) {
        my($x, $y, $z) = @coords;
        return bar($x, $y, $z);
    }

    bar(@coords); # ok now

cheers,
Aldo

Reply via email to