I was wandering what 'solution' would be better, since I run into these kind of thing regularly and it made me curious if there would be a 'common' way to handle this.
That's not an interesting question, and until this far, none of the answers given are very helpful in answering the question.
It's also a very, very open question. You're very specific about the (hardly relevant) details -- the code --, but expect the six letters to name it, "better", you don't discuss the main thing at all.
How do you expect this forum to answer your question, if you don't describe at all what you mean by "better"? Better in which way? Faster? Less memory? Less code? Or do you measure in more subjective ways, like easier to understand (which is of course a hopeless question to ask).
If you want to advance yourself in programming, don't come up with two pieces of code, and ask others what the better code is. You'll get little out of it. Instead, analyse the pieces of code yourself, and come up with reasons why you want to one piece and why you want to use the other piece of code.
-
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.
|