Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Some of your questions compare inequivalent statements, mostly in regard of global variables.

p>while (<>) { ... } or while (my $line = <>) { ... }?
They do different things. I tend to take advantage of $_ and avoid named temporaries as much as I can, so I oftener code the former.

-w or use warnings;?
They do different things. $^W is global, warnings.pm is lexically scoped. The backward compatibility issue matters. Situational, for me.

sub CONSTANT () { ... } or use constant CONSTANT => ...;?
I use constant ... when I'm comfortable with the all-caps convention. For something whose name doesn't follow the convention, or that will be explicitly called like a sub, I define the sub.

my ($foo, $bar) = @_; or my $foo = shift; my $bar = shift;?
The two are very different. The former leaves @_ unaltered. I shift when I want to remove items so that @_ can be treated as an array of similar things, as often happens in OO Perl.

for (@array) { ... } or foreach (@array) { ... }?
I use for with the pronoun, foreach if named. Blind acceptance of the perldoc recommendations and examples.

print 'foo'; or print('foo');?
A list is a list. I prefer the former. I tend to use parens as little as I can. That way, when I see them I know I've defeated operator precedence.

'simple string' or "simple string"?
Single quotes. Why invoke interpolation for nothing?

glob '*' or <*>?
I've come to prefer glob. No tricky rules about how the argument is interpreted, no confusion with reading from an open handle. I do like the compactness of diamond notation.

readline *FOO or <FOO>?
See previous question, I prefer <FOO> for its compactness.

for (keys %foo) { $_ and $foo{$_} } or while (my ($key, $value) = each %foo) { $key and $value }?
Like the while question above, I like the pronoun when I can use it. The latter has the advantage when I need to protect $_, or $value is often used in the block.

After Compline,
Zaxo


In reply to Re: Style, style, style by Zaxo
in thread Style, style, style by Juerd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found