[ Please do not top-post.  TIA ]

[EMAIL PROTECTED] wrote:
Hi

Hello,

Unless Perl is the only tool available to you in your toolbox and if you're running Linux or similar consider the "tr -s " command in a shell.

Perl also has that:

tr/,//s;


perldoc perlop


However if you are strictly limited to Perl then this stand regex works:-
echo ",,,,,"|perl -ane 's/,*/,/;print'

The OP's string also included spaces after the commas. Why are you using the -a switch, which splits the current line on whitespace and stores it in the @F array, when you are not using the @F array? Why use the -n switch and 'print' instead of just using the -p switch?

$ echo "abc" | perl -ane 's/,*/,/;print'
,abc

You are using a modifier that matches zero times so you are adding commas where none existed before.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to