A few months ago, I posted my Python script to remove trailing whitespace from a file. Somebody responded with a Perl 1-line code that does the same thing.
I could really use that Perl code now, anybody? Thanks.
>>1
I don't know about Perl, but here's how you do it in Vim: :%s/\s\+$//
Name:
Anonymous2012-04-05 7:27
>>3
Yeah I know that, I have it ran when I save a file, but I need to automatize it with Bash, Perl, or Python. And I don't want to loop all the lines and remove space.
>>13
Yet the >>12 version is actually useful and more featureful supporting command line arguments as well as reading from stdin plus it writes to stdout which is the sensible thing to do.
You could've used an explicit while (<>) if you wanted to be didactic or some gay bullshit. That's a Perl idiom anyway. Not using it just shows you're clueless.
It's not like your intent becomes any clearer with boilerplate like open.
Name:
Anonymous2012-04-06 21:37
>>5 >>10 >>12 >>14 sed does this so well that Perl even includes syntax that emulates sed. You'd be crazy to use anything else.
1Press CTRL+H to open Microsoft Visual Studio Enterprise Team Edition 2013TM "Search and replace" dialog. 2In "Search for:" box, enter ":b+$" (without quotes) 3Leave "Replace with:" box empty 4Select "Regular expressions" in the drop-down box under "Find options:" 5Click "Replace all" 6Masturbate furiously 7ENTERPRISE