Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Replace only selected characters

by AnomalousMonk (Archbishop)
on Oct 16, 2011 at 02:56 UTC ( [id://931726]=note: print w/replies, xml ) Need Help??


in reply to Replace only selected characters

Another, not necessarily better, way to "replace every x after the first with y" (needs Perl 5.10+):

>perl -wMstrict -le "for my $s ( 'ABC,XYZ PERL,, IS, AWESOME, INNIT', ',ABC,XYZ PERL,, IS, AWESOME, INNIT,', ',,ABC,XYZ PERL,, IS, AWESOME, INNIT,', ) { print qq{ in: '$s'}; ;; (my $t = $s) =~ s{ (?: \A [^,]* , (*SKIP)(*FAIL))? , }{}xmsg; print qq{out: '$t'}; print ''; } " in: 'ABC,XYZ PERL,, IS, AWESOME, INNIT' out: 'ABC,XYZ PERL IS AWESOME INNIT' in: ',ABC,XYZ PERL,, IS, AWESOME, INNIT,' out: ',ABCXYZ PERL IS AWESOME INNIT' in: ',,ABC,XYZ PERL,, IS, AWESOME, INNIT,' out: ',ABCXYZ PERL IS AWESOME INNIT'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://931726]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found