Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Replace the nth occurence

by AnomalousMonk (Chancellor)
on Nov 21, 2012 at 06:02 UTC ( #1004848=note: print w/replies, xml ) Need Help??


in reply to Replace the nth occurence

Another approach (\K available with 5.10+):

>perl -wMstrict -le "my $nth = 4; my $str = 'a,bb,ccc,dddd,eeeee,ffffff'; ;; --$nth; $str =~ s{ (?: , [^,]*){$nth} \K , }{|}xms; print qq{'$str'}; " 'a,bb,ccc,dddd|eeeee,ffffff'

Replies are listed 'Best First'.
Re^2: Replace the nth occurence
by ColonelPanic (Friar) on Nov 21, 2012 at 08:38 UTC

    ++. This is the most efficient approach.



    When's the last time you used duct tape on a duct? --Larry Wall

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004848]
help
Chatterbox?
Corion resurfaces. I find the Canary Islands always relaxing, at least for 7 days :)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2018-02-21 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (287 votes). Check out past polls.

    Notices?