CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Remove the last comma

 



itmajors
Novice

Aug 5, 2014, 7:56 PM

Post #1 of 2 (693 views)
Remove the last comma Can't Post

Need to remove a comma before the ) character

I tried using
$var =~ s/,\),/\),/g;

what I have now is
$var ="(a,b,c,d,e,f,),";
and I need
$var ="(a,b,c,d,e,f),";

How can i remove the , after the "f"?

Thanks


BillKSmith
Veteran

Aug 6, 2014, 4:15 AM

Post #2 of 2 (684 views)
Re: [itmajors] Remove the last comma [In reply to] Can't Post

It works for me using perl 5.16.3 under windows 7.


Code
use strict; 
use warnings;
my $var ="(a,b,c,d,e,f,),";
$var =~ s/,\),/\),/g;
print $var,"\n";


OUTPUT:

Code
(a,b,c,d,e,f),


Note: It is not necessary to escape the parenthesis in the substitution field. It works wither way.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives