What is Beauty ?, I don't know, I want to look for beauty in code effeciency,
as well as how the code looks.
Example: I need know if a specific element is in a list, I could do:
print "Found it!\n" if (grep {/^I_am_looking_for_this$/o} @List);
Sweet, short, and simple...
Yet, I do not like it... I forgot to mention that my list consists of 100_000
elements, what if 'I_am_looking_for_this' was the second one ? ...
2nd approach:
my $Found=0;
for (@List)
{
if (/^I_am_looking_for_this$/o)
{
$Found=1;
last;
};
};
print "Found it!\n" if $Found;
Hmmmmm... effective, though I don't like it, it's a hell of a lot of code,
but it will probably be faster than the first example.
Now, if I were gonna do this a lot more, I would prefer a sub:
sub IsInThere(@)
{
for (@_) {return 1 if /^I_am_looking_for_this$/o}
return 0;
};
print "Found it!\n" if IsInThere(@List);
I don't know what real beauty is, I know that I can like something I see, and reason
for efficiency...
I like to code... I like it a lot...
Thank you all for listening...
I would have used a hash by the way ;)
GreetZ!,
print "profeth still\n" if /bird|devil/;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.