Our system uses SYBASE and SAS, and we want to take the output from a SYBASE query and load them up into a SAS dataset. Now there is a SAS/DB module that costs $n 000s, where n is a good deal more than we want to spend :o) Our 'fastest' method to date involves SYBASE isql to export a fixed (and delimited) file, a sed command to reformat into something SAS would like to consume, and then the SAS load-up. However, we think that Perl DBLIB would cut out some of the file i/o and would enable a quicker system. It doesn't - though I'm guessing this is inexperience rather than a fact ... so please help.
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; }
Suffice to say $gdb is just a SYBASE database handle.

In reply to Fast morphing of SYBASE data to flat-file by singjoh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.