On Mon, 8 Sep 2003 17:53:04 -0400 "Rozengurtel, Daniel" <[EMAIL PROTECTED]> wrote:
> My problem is that if my sql had a specific order of fields to select > at the time of passing it to prepare/execute, I cannot change it even > if I sort the array before passing it to bind_columns. More than > that, since those would be keys in a hash, I should be able to print > out my hash in any way I want, which is not the case :( Maybe i have > a mistake somewhere in my thinking? Is there a reason you can't change the order of the columns before you call prepare()? Then you could use a simple array instead of a hash. > for example i create: > my $sql = "select c, b, a from foo"; > my @ClnFldsArray=('c', 'b', 'a'); # You need to preserve the column order used in the SELECT statement. # The output order can be sorted if you like. # In this case, I'd use a separate array for the output order. my @OutFldsArrays = sort @ClnFldsArray; #> # sort an array alphabetically i.e. 'a', 'b', 'c' #> if ($sort_flg eq "Y"){ #> my @tmp=sort @ClnFldsArray; #> @[EMAIL PROTECTED]; #> } #> #> print OUTFILE join('|',@ClnFldsArray)."\n"; # print header record. print OUTFILE join( '|', @OutFldsArray ), "\n"; # print header record. > Printed > in sorted form > > my %row; > my $sth = $dbh->prepare_cached($sql) || die $dbh->errstr; > $sth->execute; $sth->bind_columns( \( @[EMAIL PROTECTED] )); > while($sth->fetch) { > # print each row with | as delimiter #> # Basically should not matter what order got into hash, as long #> as i go by @ClnFldsArray order. I think.... #> print OUTFILE map "$row{$_}|", @ClnFldsArray; #> print OUTFILE "\n"; print OUTFILE map( "$row{$_}|", @OutFldsArray ), "\n"; > }#while -- Mac :}) ** I usually 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.