It's the weekend. Time to get your head out of the production-level code. But not too far - we'd go off-topic. So let's instead think about some of the worst ways to do things.
I don't mean things like `rm $file`;. I'm thinking more along the lines of a daily wtf, but for people who don't automatically think that "perl code" == "line noise". For example:
This isn't merely chomp - this is super-chomp. Whether you have one or many new lines at the end of your string, this will clear 'em all out. If you're not shaking your head in disappointment over that code, you're probably not realising that s/\n+$// does the same job - but faster, more reliably (no shell metacharacters to worry about!) and is far more portable.sub remove_newlines { my $string = shift; my $clean_string = `echo -n $string`; return $clean_string; }
Sit back, crack open your favourite beverage, share code you'd be embarrassed to check in to source control or upload to CPAN, and enjoy your weekend. :-)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: TIMTOWTDI meets Rube Goldberg
by jdporter (Paladin) on Aug 09, 2011 at 18:14 UTC | |
by chromatic (Archbishop) on Aug 09, 2011 at 22:18 UTC | |
Re: TIMTOWTDI meets Rube Goldberg
by eyepopslikeamosquito (Archbishop) on Aug 07, 2011 at 01:36 UTC | |
Re: TIMTOWTDI meets Rube Goldberg
by graff (Chancellor) on Aug 07, 2011 at 04:49 UTC | |
Re: TIMTOWTDI meets Rube Goldberg
by iguanodon (Priest) on Aug 06, 2011 at 23:14 UTC | |
Re: TIMTOWTDI meets Rube Goldberg
by Logicus (Initiate) on Aug 06, 2011 at 17:51 UTC | |
Re: TIMTOWTDI meets Rube Goldberg
by sundialsvc4 (Abbot) on Aug 08, 2011 at 21:12 UTC |
Back to
Meditations