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: Bob Willmot <bwillmot at drms_dev6 dot sbi dot com>
Subject: trailing commas in result set
Date: Oct 6 1997 1:05PM

Mabbett, Lane writes:
 > I'm trying to trim off trailing commas in my result set returned by
 > Sybase. 
 > What's wrong with my row =~/,\+//;
 > 
 > Thanks
 > 
 > %row = &dbnextrow($dbproc, 1);
 >     while (%row = &dbnextrow($dbproc, 1))
 >     {
 >     row =~ /,\+$//;

Mabbett,

%row is an associative array (aka hash) You'd need to do
something like:

%row = &dbnextrow($dbproc, 1);
while (%row = &dbnextrow($dbproc, 1)) {
    foreach $key (keys %row) {
        $row{$key} =~ s/,\+$//;  # the $ ensures it is line-ending 
    }	
    # ...
}


If there are only a few columns you need to do the comma substitution
for you can do it directly with:

$row{'column_name'} =~ s/,\+$//;

rather than looping over all columns of the select.

______________________________________
   Bob Willmot      Salomon Brothers
 bwillmot@sbi.com    (212)783-4217