On Mon, 10 Mar 2003 22:15:35 +0000 Tim Bunce <[EMAIL PROTECTED]> wrote:

> But imagine the DBI provided these two functions:
> 
> sub comma_separated_values { join ", ", @_ }
> sub comma_separated_placeholders { join ", ", ("?") x @_ }
> 
> you could then write the statement like this:
> separated
> my $sql = qq{
>         INSERT INTO table
>                ( ${\comma_separated_values(@col)} )
>         VALUES ( ${\comma_separated_placeholders(@col)} )
> };
> 
> The "... ${\...} ..." is a little magical but not hard to master.
> It's just a cute way to evaluate expressions inside a double quoted
> string. The ${...} part expects a reference to a scalar so that's
> what the backslash before the function name is for. The backslash
> takes a reference to the scalar value returned by the function and
> the ${...} then interpolates that into the string.
> 
> Perhaps we could call the functions dbi_csv and dbi_csp then we'd have
> 
> my $sql = "INSERT INTO table ( ${\dbi_csv(@col)} ) VALUES (
> ${\dbi_csp(@col)} )";

That do look purrty.  I tend to use the foreach() idiom because I
originally had to do some additional processing on the column names.
I'd momentarily forgotten the 'x' operator.  TMTOWTDI.

-- 
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.catb.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.

Reply via email to