singjoh has asked for the wisdom of the Perl Monks concerning the following question:
Suffice to say $gdb is just a SYBASE database handle.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|$fi +eld3"); print FILE "$line\n"; } $runok = 1 ; } sub sasify() { my ($in) = @_; $in =~ s/^\| *//g; # remove end marker and trailing spaces (SY +BASE) $in =~ s/ *\|$//g; $in =~ s/NULL//g; # destroys nulls (possible effect on names i +ncluding 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 emp +ty the write to .) return $in; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fast morphing of SYBASE data to flat-file
by davis (Vicar) on Mar 13, 2003 at 16:57 UTC | |
by VSarkiss (Monsignor) on Mar 13, 2003 at 17:40 UTC | |
by tye (Sage) on Mar 13, 2003 at 19:06 UTC | |
|
Re: Fast morphing of SYBASE data to flat-file
by VSarkiss (Monsignor) on Mar 13, 2003 at 17:53 UTC | |
|
Re: Fast morphing of SYBASE data to flat-file
by runrig (Abbot) on Mar 13, 2003 at 17:53 UTC | |
|
Re: Fast morphing of SYBASE data to flat-file
by Abigail-II (Bishop) on Mar 13, 2003 at 23:31 UTC | |
by mpeppler (Vicar) on Mar 17, 2003 at 16:44 UTC |