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: jander at lehman dot com (Jim Anderson)
Subject: Re: SybPerl
Date: Nov 8 1995 3:10PM

>>>>> "E" == Ernest Fan  writes:

E> Hi all, SybPerl is totally new to me, can anyone send me some
E> script of SybPerl so that I can study it and learn how to use it?
E> Any pointers are also appreciated!

Take a look at the examples in the eg directory. Most of them are
perl5 examples.

And here's a simple one.

#!/usr/local/perl
#
# sample.pl

BEGIN {
    $ENV{'SYBASE'}  = '/usr/local/sybase';
}
use Sybase::DBlib;

$user   = 'my_user';
$pwd    = 'my_pswd';
$server = 'MY_SERVER';
$db     = 'my_db';

$dbp = new Sybase::DBlib $user, $pwd, $server;
$dbp->dbuse($db) || die "'use' failed for $db: $!\n";

while () {
    next if /^\s*$/;
    ($fullname,$id) = unpack('A23A*',$_);
    @tmp = split(/\s+/,$fullname);
    $fname = shift(@tmp);
    $lname = join(' ',@tmp);
    $uid = '';
    $dbp->sql("select distinct userid from users where lastname = '$lname' and firstname like '$fname%'", 
	      sub { $uid = shift } );
    push(@isThere,"$lname:$fname:$id"), print "=>$lname:$fname:$id:$uid\n", next if $uid;
    push(@inserted,"$lname:$fname:$id");
    
    $sql = "insert users (userid, lb_dispatch_group, lastname, firstname, site_id) 
                   values(0,      '$_',              '$_',     'Alias',   'JUNK')";
    $sql =~ s/\s+/ /g;
    $dbp->sql($sql);
}

foreach (sort(@inserted)) {
    ($lname,$fname,$id) = split(/:/);
    $uid = '';
    $dbp->sql("select distinct userid from users where lastname = '$lname' and firstname like '$fname%'", 
	      sub { $uid = shift } );
    push(@failed,$_), next if !$uid;
    push(@succeeded,"$lname:$fname:$id");
}

$dbp->dbclose();

print "Insertion failed for the following users in the users table:\n\n" if @failed;
foreach (@failed) {
    ($lname,$fname) = split(/:/);
    print "$lname, $fname\n";
}

print "\n\nThe following users were already in the users table:\n\n";
foreach (sort(@isThere)) {
    ($lname,$fname,$id) = split(/:/);
    print "$lname, $fname, $id\n" if !$uid
}

print "\n\nThe following users were inserted into the users table:\n\n";
foreach (sort(@isThere)) {
    ($lname,$fname,$id) = split(/:/);
    print "$lname, $fname, $id\n" if !$uid
}

__DATA__
Mark Schivley          schivley
Sandeep Kapoor         skapoor
Terri Evans            tevans