in reply to Style, style, style
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Style, style, style
by Anonymous Monk on Sep 08, 2002 at 03:51 UTC | |
by dws (Chancellor) on Sep 08, 2002 at 03:57 UTC | |
by belden (Friar) on Sep 08, 2002 at 18:02 UTC | |
by Aristotle (Chancellor) on Sep 10, 2002 at 16:25 UTC | |
by cybear (Monk) on Sep 10, 2002 at 15:42 UTC |
In Section
Meditations