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 peppler dot org>
Subject: Re: Sybperl, loops, and unfortunate information retention.
Date: May 17 2000 5:12PM

Jamie Belanger writes:
 > As follows is a portion of code that I'm attempting to use to gather hourly
 > statistics for a few of our servers... When I run the script, the Picard
 > loop executes correctly. However, the elsif for Data and Dax both spit out
 > sybase error messages which indicate that they are attempting to use
 > Picard's database names still (Attempt to locate entry in sysdatabases for
 > database '_______' by name failed - no entry found under that name. Make
 > sure that
 > name is entered properly). All of the variables are unique, and I was
 > wondering if there is something quirky with attempting multiple sybase
 > sessions within one script?

I think your problem is that you are using global variables
everywhere, and so you don't get the proper cleanup that you would
normally expect. In addition you are using == to test for string
equality. Had you used the -w switch and the "use strict" pragma this
would have been immediately obvious.

I would do this like this:

foreach my $server (@servers){
  if($server eq "picard") {   # string comparison is "eq" not "=="!
     my @picard = qw(billing toll1 toll5 toll6 toll9 rating);
     my $X = Sybase::CTlib->ct_connect($uid, $passwd, $server);

     foreach my $database_picard (@picard){
         $X->ct_sql("use $database_picard");
         $X->ct_execute($SQL);

         while($X->ct_results($restype) == CS_SUCCEED){
               next if(!$X->ct_fetchable($restype));
               while(@dat_picard = $X->ct_fetch){
                  push(@translog_picard, @dat_picard);
               }
        }
    }
    # Because of the "my $X" above the connection to this server is
    # automatically closed here
  } elsif ($server eq "data"){
      my @data= qw(admin debit5 oecs);
      my $Y = Sybase::CTlib->ct_connect($uid, $passwd, $server);

	etc...

Michael
-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@peppler.org    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com