Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Style, style, style

by Arien (Pilgrim)
on Sep 08, 2002 at 05:51 UTC ( #195986=note: print w/replies, xml ) Need Help??

in reply to Style, style, style

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>?


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://195986]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2021-06-24 10:31 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (125 votes). Check out past polls.