I never use while (my $line = <FH>) because while (<FH>) is "shorthand" for: while (defined( $_=<FH>)), and the defined can sometimes be important if your last entry in a file is a 0 without \n afterwards. And normally, I don't want to miss a single zero at the end which could even happen with <> if you pipe in a file.
I don't like <> without a filehandle in larger codes, I prefer doing it the long way round with open(FH, ... while (<FH>) or the like. But with short scripts (or throw-away-scripts) <> often seems ok.

-w or use warnings: with perl5.0, I prefer -w, with perl >= 5.6 I use warnings because it is not global. But for production code, i remove -w or use warnings with a comment because I don't want an inocent user be confronted with strange "error messages" they don't understand.

I prefer use constant CONSTANT => ...; because it makes clear that I want to use a constant and not a sub (although internally it all is about the same).

my ($foo, $bar) = @_; or my $foo = shift; my $bar = shift;?
I use both, but prefer the first solution, because then I've got an entry in a subroutine at the very beginning, which may keep the code a bit more readable. But if you don't know how many parameters are coming, I sometimes use shift in a loop (with commenting a lot why to do so).

In bigger codes, I prefer using print as a function (print(...)), but I don't know why. One reason may be that with a good syntax highlighning editor, you can easier find matching parantheses...

glob '*' or <*>: since I have to work a lot with perl5.005_03, I prefer using the module File::DosGlob. With perl >= 5.6, I prefer glob

readline *FOO or <FOO>?: I always use <FOO>, because in my eyes, it is more idiomatic. But for a beginner, readline might be easier to understand in an existing code

foreach vs. while each: It just depends on what I need. If I need some way of sorting, I have to use foreach. If not, then I nearly always use each, because with bigger datastructures, it might be faster, and $key and $value are imho better namens than $key and $foo{$key}.

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"


In reply to Re: Style, style, style by strat
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.