laziness, impatience, and hubris | |
PerlMonks |
Re: Style, style, styleby Arien (Pilgrim) |
on Sep 08, 2002 at 05:51 UTC ( [id://195986]=note: print w/replies, xml ) | Need Help?? |
while (<>) { ... } or while (my $line = <>) { ... }? The implicit $_, unless spelling things out makes it clearer. -w or use warnings;? use warnings; whenever the Perl version lets me. sub CONSTANT () { ... } or use constant CONSTANT => ...;? The latter in general, to avoid confusion about intended use. my ($foo, $bar) = @_; or my $foo = shift; my $bar = shift;? Option 1, unless there a $self I'll shift of, I'm using default values, or there's a hash being passed by value. for (@array) { ... } or foreach (@array) { ... }? Both, depending on what I'm doing. It could even be .... for (@array);. print 'foo'; or print('foo');? No parens please, I'll put them in on the rare occasion I need them. 'simple string'; or "simple string"? Interpolated unless I explicity don't want it. glob '*' or <*>? Depending on who will see the code. A lot of people don't know about <*>. readline *FOO or <FOO>? <FOO>. for (keys %foo) { $_ and $foo{$_} } or while (my ($key, $value) = each %foo) { $key and $value }? That would be door no. 1, please, unless %foo is tied to something like a database, to avoid getting Perl all cranky. :-) — Arien
In Section
Meditations
|
|