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":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.