Michael Peppler
Sybase Consulting
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
Sybase on Linux FAQ
Sybperl FAQ
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 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  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" =, "other col name" =


 > 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 Peppler         -||-  Data Migrations Inc.    -||-
Int. Sybase User Group  -||-
Sybase on Linux mailing list: