Perl is beautiful

Random irrelevance that just didn't fit into other forums. Talk about anything.

Moderator: Talkative People

Post Reply
User avatar
bbguimaraes
Chaos Rift Junior
Chaos Rift Junior
Posts: 294
Joined: Wed Apr 11, 2012 4:34 pm
Programming Language of Choice: c++
Location: Brazil
Contact:

Perl is beautiful

Post by bbguimaraes »

OK, I'm currently in a state of absolute boredom. And it's been 10 days since the last post on the Off-Topic forum. On my daily routine of exploring the dark and moist corners of computing, I stumbled on this Perl one-liner (I'm including the part used to call it from vi, just to make it more beautifully cluttered):

Code: Select all

:'<,'>!perl -pe '$i||=0;s/(billy)9/\1$i/;++$i'
This will take a block of text selected on vi and replace the first occurrence of 'billy9' on a line by 'billy0', the second on other line by 'billy1', and so on. 'billy' here is completely random: it's there just to replace the also completely random word I needed to replace on my code (and it's the name of my dog). And just to increase the unusefulness of this post, here is a prettier, more cluttered and more efficient version:

Code: Select all

:'<,'>!perl -pe '$i||=0;s/(?<=billy)9/$i/;++$i'
Have a nice day.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Perl is beautiful

Post by Falco Girgis »

:lol: You sick bastard!
Post Reply