.. (which I happen to think is very ugly) I can use sprintf:## silly example without DBI quoting my $sql = "insert into mytable (" . join(",", @columns) . ") values (" . join(",", @values) . ")";
So in this case, I really like the mini string-templating possiblities of s/printf, but of course I don't want to print the SQL statement to the screen, I want to send it to the database. Hence, sprintf.my $sql = sprintf "insert into mytable (%s) values (%s)", join(",", @columns), join(",", @values);
This is nothing special about SQL statements, only that I often want to include the result of nontrivial expressions (i.e, not just $string) in the string. I can't interpolate a join statement (easily) inside a double-quoted string, and stringing together concatenation operations is ugly, so I use sprintf, which is easier to read (for me at least).
blokhead
In reply to Re: Why SprintF?
by blokhead
in thread Why SprintF?
by JasonCgi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |