go ahead... be a heretic | |
PerlMonks |
Re: Style, style, styleby dws (Chancellor) |
on Sep 08, 2002 at 02:19 UTC ( [id://195959]=note: print w/replies, xml ) | Need Help?? |
1. while (<>) { ... } or while (my $line = <>) { ... }?
I use both, depending on whim and my assemement of readability.
2. -w or use warnings;?
-w, but only because of muscle memory.
3. sub CONSTANT () { ... } or use constant CONSTANT => ...;?
use constant CONSTANT => ...;
4. my ($foo, $bar) = @_; or my $foo = shift; my $bar = shift;?
I always shift $self. Whether or not to shift the other args or use array assignment kind of depends. Whim again, I'm afraid.
5. for (@array) { ... } or foreach (@array) { ... }?
foreach. My undergrad degree was in Math.
6. print 'foo'; or print('foo');?
No parens unless needed for precedence.
7. 'simple string'; or "simple string"?
Double quotes.
8. glob '*' or <*>?
opendir(); readdir(); closedir();
9. readline *FOO or <FOO>?
<FOO>
10. for (keys %foo) { $_ and $foo{$_} } or while (my ($key, $value) = each %foo) { $key and $value }?
Depends on whether or not %foo is tied to a DBM. I use the 'each' form on DBMs, having been burned once by pulling all keys into memory on a big DBM.
In Section
Meditations
|
|