Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Re: Problem with code

by SamueD2 (Novice)
on Feb 05, 2003 at 15:49 UTC ( [id://232833] : note . print w/replies, xml ) Need Help??

in reply to Re: Problem with code
in thread Problem with code

Can you explain to me what you are doing with my $placeholders = join(',', ('?') x @fields);

Replies are listed 'Best First'.
Re^3: Problem with code
by Aristotle (Chancellor) on Feb 05, 2003 at 20:25 UTC
    Well, given a list on the left hand side, x will produce an output list which consists of as many copies as you specify with the right hand side operand. The right side is evaluated in scalar context, and we're using an array there; the result is the number of elements in that array. So
    ('?') x @fields

    will produce a list which has exactly as many elements as @fields, where each element is a question mark. So given @fields = qw(foo bar baz) I have created a list like ('?', '?', '?')

    Then I join them using a comma as a separator, giving me, in the previous example, '?,?,?'.

    As explained in detail in the DBI documentation section on placeholders, I do that so I don't have to generate a new SQL statement over and over; instead, I generate a single one, where I let the driver fill in the values I supply to execute().

    Makeshifts last the longest.