|
|
sybperl-l Archive
Up Prev Next
From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: trailing commas in result set
Date: Oct 6 1997 3:05PM
Mabbett, Lane wrote:
>
> 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))
> {
### Add this
foreach (keys(%row)) {
$row{$_} =~ s/,\s*$//; # remove trailing commas,
# potentially with space between the comma and the end
# of the string
}
###
> row =~ /,\+$//;
> print "$row{'prov_name'}, , ";
> print "Specialty: $row{'description'}, ";
> print "$row{'prov_address1'}, ";
> print "$row{'prov_address2'}, ";
> print "$row{'prov_city'} ";
> print "$row{'prov_state'}, ";
> print "$row{'prov_zip'}, ";
> print "$row{'prov_phone'}, ";
> print "", "\n";
> }
Your regexp was incorrect (you were looking for a literal + after
the comma) and you need to apply it to each of the elements of the
hash, not to the hash itself...
Michael
--
Michael Peppler -||- Data Migrations Inc.
mpeppler@datamig.com -||- http://www.mbay.net/~mpeppler
|