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:
sub remove_newlines
{
my $string = shift;
my $clean_string = `echo -n $string`;
return $clean_string;
}
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.
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. :-)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|