in reply to Re: @array[1] is valid??
in thread @array[1] is valid??

I did not answer it because I never disputed whether a single element slice rvalue does the right thing in the first place.

Note (again) that I'm specifically talking about the case with a constant index. Maybe my imagination is indeed limited. I'm honestly tempted to grep all of CPAN to find out whether anyone else has ever found it useful.

But let's accept your argument that it's in the spirit of TMTOWTDI to use it that way as an lvalue and therefor shouldn't be warned against when other similar ways aren't. Let's also accept your agument that it doesn't behave any differently than $array[42] as an rvalue.

I offer that it is a fact that a (even slightly) seasoned Perl programmer will instinctively use the $array[42] notation.

Then is there any argument you can make against warning about it when used as an rvalue (but not lvalue)?

(PS: If you want to talk about too many warnings, you're invited to talk about "used only once"..)

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: @array[1] is valid??
by Abigail-II (Bishop) on Aug 05, 2003 at 21:18 UTC
    Let's also accept your agument that it doesn't behave any differently than $array[42] as an rvalue.

    I offer that it is a fact that a (even slightly) seasoned Perl programmer will instinctively use the $array[42] notation.

    Then is there any argument you can make against warning about it when used as an rvalue (but not lvalue)?

    The fact that most Perl programmers will prefer $array[42] over @array[42] is partially habit, but it's also influenced by this warning being discussed. Seasoned Perl programmers will use warning, if only during development, and if a programmer has two options of doing something, and one option issues a warning, which option do you think will be mostly used?

    Let's not forget that Larry himself decided that $array[42] isn't right, and that it's now going to be @array[42] in perl6. Should then perl5 warn? I don't think so.

    Furthermore, if you accept that (at least in rvalue context), both @array[42] and $array[42] are the same, why should there be a warning for one? If you cannot make a mistake, why suggest to the programmer he could have made one?

    Abigail