sub main { my $gdb = clsDatabase2->new(datasource => clsEnvironment2->new->datasources->{"DBSOURCE"}); my $outfile = "temp.out"; my $sql = " ... Some Query ..." ; my @rowrefs = $gdb->nsql($sql, "ARRAY") ; $gmod->log("Building new file."); open(FILE, ">$outfile") || die "$0: Cannot open file '$outfile' for writing: $!\n"; foreach my $rowref (@rowrefs) { my $field0 = sasify($rowref->[0]); my $field1 = sasify($rowref->[1]); my $field2 = sasify($rowref->[2]); my $field3 = sasify($rowref->[3]); my $line = sasify("$field0|$field1|$field2|$field3"); print FILE "$line\n"; } $runok = 1 ; } sub sasify() { my ($in) = @_; $in =~ s/^\| *//g; # remove end marker and trailing spaces (SYBASE) $in =~ s/ *\|$//g; $in =~ s/NULL//g; # destroys nulls (possible effect on names including NULL, shame :o) ) $in =~ s/\| */|/g; # left trim fields $in =~ s/ *\|/|/g; # right trim fields $in =~ s/^\|/.|/g; # Check first field (if empty then write to .) $in =~ s/\|{2}/|.|/g; # Write Empty fields to . (double pass) $in =~ s/\|{2}/|.|/g; $in =~ s/\|$/|./g; # Finally check the last field (if its empty the write to .) return $in; }