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: Returning duplicate names
Date: Sep 8 1999 6:39PM

deridder@pcisys.net writes:
 > In the following code I am monitoring connections.  The problem is when I
 > submit the sql in perl it only gives back one of the 'name' columns and
 > leaves out the sl.name.  I am assuming because they are the same name?  How
 > would I remedy this.  When I submit the sql from isql I get all values.

All the values are returned to perl, but because you ask for a hash
return, so we create a hash based on the column name. You need to
disambiguate the column names in the select, or use the array
form. You disambiguate the names with the 

	select "col_name" = sp.pid, "other col name" = sl.name

syntax.

 > 
 > PS: The code line print "$dat{$key}   "; I use to put spaces between the
 > values.  How do I check when there is a new row of values returned.  I don't
 > want to put spaces after the last value on each row.  

You can't really check this in the foreach loop, but there are various 
ways that you can achieve this, one of which is using a $first
variable, like this:

     while(%dat = $X->ct_fetch(CS_TRUE)) {
	$first = 1;
         foreach $key(keys %dat) {
	    if($first) {
		print "$dat{$key}";
		$first = 0;
	    } else {
                 print "   $dat{$key}";
	    }
         }

Not *very* elegant, but it works :-)

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