sub make_select_query { my ($table, $select_fields, $conditions) = @_; my $query = "SELECT "; if ( defined $select_fields ) { if ( ref($select_array) eq "ARRAY" ) { $query .= join ",", @$select_array; } else { $query .= $select_fields; } } else { $query .= "\*"; } $query .= " FROM " . $table; # only put the where and conditions in the query string # if conditions are present if (keys %$conditions) { $query .= " WHERE "; foreach my $key (keys %$conditions) { push @conds, $key . "=\'" . $conditions->{$key} . "\'"; } } $query .= join " and ", @conds; return $query; }