in reply to DBI and mysql query formatting

I can't comment on the SQL but this will ensure you always have the same order:
my @keys = keys %test; my $str = join(", ", @keys); my $val = join(", ", map { $test{$_} } @keys);

Replies are listed 'Best First'.
Re^2: DBI and mysql query formatting
by kcott (Archbishop) on Dec 06, 2013 at 11:00 UTC
    "... this will ensure you always have the same order: my @keys = keys %test;"

    Actually, that's only true for versions of Perl prior to 5.18.0. From perl5180delta: Hash overhaul:

    "By default, two distinct hash variables with identical keys and values may now provide their contents in a different order where it was previously identical."

    I have v5.18.1 - here's a few example runs:

    $ perl -Mstrict -Mwarnings -E 'my %x = map { $_ => 1 } "A" .. "E"; my +@y = keys %x; say "@y"' A D E C B $ perl -Mstrict -Mwarnings -E 'my %x = map { $_ => 1 } "A" .. "E"; my +@y = keys %x; say "@y"' D E C B A $ perl -Mstrict -Mwarnings -E 'my %x = map { $_ => 1 } "A" .. "E"; my +@y = keys %x; say "@y"' D E B A C

    Either a sort on the keys, or even a hard-coded list, would probably provide a more robust solution.

    -- Ken

      Yes, I agree. But the goal of the OP is to have the same order for the $str and $val, not for every run.
        But the goal of the OP is to have the same order for the $str and $val, not for every run.

        That's what values guarantees:

        [...] So long as a given hash is unmodified you may rely on keys, values and each to repeatedly return the same order as each other. [...]

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)