Any opinions expressed herein are from someone with about a month's exposure to Perl working with it during what little free time I have. Saying that, here goes from my still "new to Perl" point of view... :)

while (<>) { ... } or while (my $line = <>) { ... }?

I generally use the former right now for ease of typing although I'm beginning to have some notions seeping into my head about lexical scoping of $_ which I think I need to learn more about!

-w or use warnings;?

I started with -w for my first few programs just because I'd read it on here, then I changed to use warnings; after some interesting discussions on here and due to the fact the Perl code I'm writing is always designed to be run on a version of Perl that supports it.

sub CONSTANT () { ... } or use constant CONSTANT => ...;?

This would have to be the latter as I didn't really know about the former until now :) Time to research the differences if any! (Hopefully there will be lots of wise words in this thread)

my ($foo, $bar) = @_; or my $foo = shift; my $bar = shift;?

Originally I'd have chosen the first option but since I've been trying to play around with packages and OO programming in Perl I've come to understand that shift isn't as scarey as it first looked so now I'd choose the latter.

for (@array) { ... } or foreach (@array) { ... }?

Easy one! The first because it has fewer keystrokes, I'm lazy, and right now I'm the only one who will ever see my Perl so there is nothing to be gained (AFAIK) in using the extra four letters. (Enlightenment is welcomed if there *is* a difference at all)

print 'foo'; or print('foo');?

Generally without the parentheses unless I have some scoping issue. Speaking of scoping issues that *really* hurt me the first time it happened but now I'm more wary!

'simple string' or "simple string"?

Always single quotes unless I know there is some variable in the string that I want interpolated, just seems safer that way to me right now.

glob '*' or &lt;*&gt;?

At the moment I'd pick glob '*' because my limited experience of glob is currently just from reading the Llama book so I like to be reminded that it's there and I still don't "get" what it does 100%

readline *FOO or &lt;FOO&gt;?

I'd choose the latter here simply because the former is a notation I hadn't seen much of before.

for (keys %foo) { $_ and $foo{$_} } or while (my ($key, $value) = each %foo) { $key and $value }?

Again I'd choose the former but there is still some tingling feeling running up my spine that I'm not entirely conversant with the scoping of $_ and what I can and can't do with it! :)

Nice thread,
Neil

In reply to Re: Style, style, style by Nemp
in thread Style, style, style by Juerd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.