in reply to Re: DBI SQL adding array of values
in thread DBI SQL adding array of values

if (scalar @data = scalar @table) {
Oops. Wrong operator. You want ==.

And use of scalar is unnecessary — though it doesn't hurt.

if (@data == @table) {

Replies are listed 'Best First'.
Re^3: DBI SQL adding array of values
by radiantmatrix (Parson) on Oct 29, 2004 at 17:09 UTC

    Yeah, @data == @table works today, but I'm always worried that someday it will mean "if the contents of @data match the contents of @table. Better to explicitly compare the number of elements, as scalar's behavoir is less likely to change.

    radiantmatrix
    require General::Disclaimer;
    "Users are evil. All users are evil. Do not trust them. Perl specifically offers the -T switch because it knows users are evil." - japhy

      Your concern is without foundation. The behaviour of the == operator applying a scalar / numeric context to both of its operands is not going to change in perl 5 and will not in perl 6 either. Feel safe in knowing @data == @table is unambiguous and is not going to change on you.

      Also, the question of comparing two arrays for equality is more complex than you appear to think. If you'd like to hear more about equality, speak up. In a new SoPW about the different meanings of equality in comparing two arrays. Its a bigger subject than a single response to an unrelated thread merits.

        the question of comparing two arrays for equality is more complex than you appear to think
        I am actually well aware of the complexities of testing for equalities in arrays. But I have also used (admittedly archaic) scripting languages where array1 == array2 tested for byte-length equality, or where the same tested equality for all elements. Either of those cases were not what the OP was looking for, but for a "number of elements" comparison.

        It is, however, nice to know that there are no plans to alter the current behavior of @array1 == @array2 in Perl 6; thank you for that nugget.

        radiantmatrix
        require General::Disclaimer;
        "Users are evil. All users are evil. Do not trust them. Perl specifically offers the -T switch because it knows users are evil." - japhy