Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Style, style, style

by Arien (Pilgrim)
on Sep 08, 2002 at 05:51 UTC ( [id://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>?

<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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-26 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found