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: John Gilmore-Baldwin <john at dwx dot com>
Subject: Re: trailing commas in result set
Date: Oct 6 1997 2:41PM

Perhaps I'm missing something, but shouldn't the command be:

$row{$key} =~ s/,$//; #remove comma at end of string

Where does the "\+" come in?  This would cause it to search for a comma
followed by a plus sign anywhere in the string.



>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