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: Very Odd Problem
Date: Mar 29 2004 9:36PM

On Mon, 2004-03-29 at 12:29, Delegal, Darin wrote:
> Maybe Michael can shed some light on this one. I do know that
> CS_SUCCEED as well as most of the Sybase constants (?) are exported by
> CTlib.pm and are actually function calls, however, I haven't been able
> to call them directly without the qualifier. CS_SUCCEED is indeed a
> subroutine and is included in a "use subs" pragma in the CTlib.pm. I'm
> just not sure why it isn't callable bare without "&" and () since it's
> included in the list of standard exports also.

All of the CS_xxx symbols are minimal subroutines that are autoloaded in
CTlib.pm, which calls the constant() function in CTlib.xs to get the
actual value that the symbol is supposed to have.

Inside of the Sybase::CTlib package itself these symbols aren't always
understood by the parser as subroutine calls, hence the need to use
&CS_SUCCEED or CS_SUCCEED() to make sure that the perl parser
understands things correctly.

However, in your code (e.g. in your error handlers, etc.) you *should*
be able to always use the simple CS_SUCCEED format. For example, when
calling ct_config() to get the OpenClient version:

$ret = ct_config(CS_GET, CS_VER_STRING, $string, CS_CHAR_TYPE);

Here CS_GET, CS_VER_STRING and CS_CHAR_TYPE are evaluated to subroutine
calls that return the values of the respective symbols, pulled from the
Sybase include files when Sybase::CTlib is built.

This was done originally (way back in 1995, IIRC) so that C programmers
that are used to these CS_xxx symbols would feel at home, and so
Sybase::CTlib could be as close as possible to the Sybase C level API -
back then a lot of the users picking up perl and/or sybperl already knew
OpenClient from C (or maybe I did it that way because it was what I was
comfortable with, being a C programmer myself...) 
These days a lot (most?) of perl programmers that use sybperl have never
done any OpenClient programming in C, which makes all of these CS_xxx
symbols and ct_xxx() API calls a little trickier to use and understand.
If that is the case then I'd like to recommend the Sybase::Simple module
that takes care of most of the low-level stuff for you (Sybase::Simple
is what I use most of the time for simple to medium level complexity
scripts.)

Michael

> -----Original Message-----
> From: owner-sybperl-l@peppler.org [mailto:owner-sybperl-l@peppler.org]On
> Behalf Of r huber
> Sent: Monday, March 29, 2004 3:08 PM
> To: sybperl-l@peppler.org
> Subject: RE: Very Odd Problem
> 
> 
> Thanks. I did as you suggested and it worked great. 
> 
> I am somewhat new to perl and sybperl and do not
> understand the use of the & in this context. I had
> thought something like &CS_SUCCEED  would be a
> subroutine call to CS_SUCCEED. Is CS_SUCCEED a
> subroutine; I must admit I am somewhat confused.
> Regards,
> Robert
> -----Original Message-----
> From: owner-sybperl-l@peppler.org
> [mailto:owner-sybperl-l@peppler.org]On
> Behalf Of Delegal, Darin
> Sent: Monday, March 29, 2004 2:23 PM
> To: sybperl-l@peppler.org
> Subject: RE: Very Odd Problem
> 
> 
> According to the CTlib reference guide, a server
> callback routine must retrun CS_SUCCEED. Client
> message routines must return either CS_SUCCEED or
> CS_FAIL. Since you're not specifying a return value
> from the functions, perl is using the last result
> value within the function (most likely the return
> value from the print statements) which is confusing
> the API.
> 
> If you simply add "return &CS_SUCCEED;" at the end of
> each callback routine, things will work as intended.
> 
> Darin Delegal
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Finance Tax Center - File online. File on time.
> http://taxes.yahoo.com/filing.html
-- 
Michael Peppler                              Data Migrations, Inc.
mpeppler@peppler.org                       http://www.peppler.org/
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or 
long term contract positions - http://www.peppler.org/resume.html