PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at mbay dot net>
Subject: Re: update Sybase from text file using SYBPERL
Date: Sep 10 1997 4:51PM

THis sort of thing should go to the sybperl mailing list, rather than
the SQSH mailing list...

Lachlan Dunlop wrote:
> 
> Hello list,
> 
> This question is to do with sybperl.
> 
> I have enclosed a script I'm writing to parse a text.  The parsing is
> fine (not pretty though). I am at the point where I am trying to insert
> these columns into a table.
> 
> How do I link the variables $h## to fields in the table.
> 
> Any simple examples out there so I can get the idea.
> 
> Thanks
> 
> Lach
> 
> parse script follows:
> #!/usr/bin/perl

use Sybase::DBlib;

$dbh = new Sybase::DBlib 'user', 'pwd', 'server';

> 
> open (INVDATA, "/usr2/invdata/in970909.inv") or die "Can't open invoice
> file: $!\n";
> 
> while () {
>         $a1=substr($_,0,8);             # order no
>         $a2=substr($_,8,3);             # line no
>         if ($a2 eq '999') {
>                 $h1=substr($_,11,6);    # Packing slip No
>                 $h2=substr($_,17,8);    # Invoice No
>                 $h3=substr($_,25,6);    # customer id
>                 $h4=substr($_,31,1);    # carrier
>                 $h5=substr($_,32,20);   # freight text
>                 $h6=substr($_,52,16);   # po no
>                 $h7=substr($_,68,6);    # po date
>                 $h8=substr($_,74,6);    # ship date
>                 $h9=substr($_,80,6);    # invoice date
>                 $h10=substr($_,86,6);   # order date
>                 $h11=substr($_,92,6);   # blank date
>                 $h12=substr($_,98,8);   # amount 1
>                 $h13=substr($_,106,8);  # invoice total
>                 $h14=substr($_,114,8);  # amount 2
>                 $h15=substr($_,122,8);  # freight total
>                 $h16=substr($_,130,8);  # amount 3
>         }
>         else {
>                 $l1=substr($_,11,6);
>                 $l2=substr($_,17,8);
>                 $l3=substr($_,25,6);
>                 $l4=substr($_,31,8);            # line cost
>                 $l5=substr($_,39,6);            # order quantity
>                 $l6=substr($_,45,6);            # ship quantity
>                 $l7=substr($_,51,6);            # back order Quantity
>                 $l8=substr($_,57,8);            # amount 6
>                 $l9=substr($_,65,8);            # unit price
>                 $l10=substr($_,73,8);           # extended price
>                 $l11=substr($_,81,8);           # amount 7
>                 $l12=substr($_,89,2);           # gl period
>                 $l13=substr($_,91,105);         # part no & description
>                         $l14=substr($l13,0,12); # part no
>                         $l15=substr($l13,12,40);# description 1
>                         $l16=substr($l13,52,40);# description 2
> 
>         }
>     #  INSERT DATA INTO SYBASE TABLE HERE

    $dbh->dbcmd(<dbsqlexec;
    while($dbh->dbresults != NO_MORE_RESULTS) {
        ;
    }

> }


You should probably add better error handling, though.

Michael
-- 
Michael Peppler       -||-  Data Migrations Inc.
mpeppler@datamig.com  -||-  http://www.mbay.net/~mpeppler