develooper Front page | perl.perl5.porters | Postings from March 2000

Re: hook for qs// operator for embedded SQL?

M.J.T. Guy
March 20, 2000 01:12
Re: hook for qs// operator for embedded SQL?
Message ID:
"Joseph N. Hall" <> wrote
> Well, yes, first you could (in theory) make interpolation context-sensitive.
> Again:
>   @result = qs/select @cols from $table where $col = $val/
> Here, @cols needs to be ,-separated, $table and $col need one kind of
> interpolation, and $val needs another.

So it looks like you want to define your qs function to have a
sprintf()-like first argument:

   @result = qs("select %a from %t where %c = %v", \@cols, $table, $col, $val);

where %a, %t etc trigger the appropriate form of interpolation.
(Of course, % is a daft choice for escape character  -  I've just used
it to illustrate the analogy with sprintf().)

And it can look quite neat if you make your query proformas objects:

     my $query = new Query("select %a from %t where %c = %v");
     @result = $query->qs(\@cols, $table, $col, $val);

So my point is not so much "The qs() syntax is too valuable to let you have
it" (though I suspect that would be the general p5p reaction) as
"The syntax doesn't do anything you can't do already".    You don't
need any new syntax;  you need new semantics, and that can be wrapped
in what I've been calling the qs() subroutine.

Mike Guy Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About