In case you're using the DBI (which you should) you can do this rather simple:
my @columns = qw#A B#;
foreach (@columns)
{
my $rows = $DBH->selectcol_arrayref ("SELECT $_ FROM $table") or d
+ie $DBH->errstr ();
print STDOUT join ('|', @$rows), "\n";
}
You can use a statement handle instead of the sql-query-string, but I don't know if placeholders are supported.. Maybe somebody else knows?! But I guess you can trust your hand-build array. This method has a lot of overhead so for performance-relevant tasks I would seek some other solution..
Regards,
-octo