my $col_string = ''; for my $var ( sort {$$href{$a} <=> $$href{$b}} keys %$href ) { $col_string .= "$var,"; } chop $col_string; # remove final comma
I always view the chopping of a trailing comma in building an SQL statement as something of a Red Flag. It usually means that a join (in the Perl sense) is called for. For instance, the above snippet is better written as
my $col_string = join( ',', sort {$href->{$a} <=> $href->{$b}} keys %$href );
• another intruder with the mooring in the heart of the Perl
In reply to Re^4: Building SQL Query on the fly (join is your friend)
by grinder
in thread Building SQL Query on the fly
by hallikpapa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |