Which is better, a chainsaw, an awl, or a rasp?
Which of these constructs is preferable?
# 1
print 2 + 2;
# 2
my $result = 2 + 2;
print $result;
# 3
print 4;
# 4
use constant FOUR => (2 + 2);
print FOUR;
# 5
sub sum { $_[0] + $_[1] }
print sum(2, 2);
With so little context, this is a meaningless question. What are you trying to accomplish? Answer that, and it's possible to evaluate these approaches.
(Code reuse is all well and good, but I'm not going to write an object oriented framework for a one-liner designed to strip out high bit characters.)
Update (Mon Oct 15 16:06:13 UTC 2001): Okay, this is unnecessarily short and terse. I apologize. Here are some questions I would ask before giving judgment:
- Is this a cut-down example of the type of thing that might be done?
- In what type of program does this run?
- How often might this message be displayed?
- Who is expected to see this message?
- Are there other, similar messages?
- Is this in a program or a module?
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.