It is the mark of a bad programmer to not spend enough time considering their alternatives, and how they want to do things.

A really bad programmer may hear a problem and start working on it before even having heard the full problem through.

And it isn't Perl that is at fault. Every language will present you with choices, and the tradeoffs are not always obvious. I personally learn about the tradeoffs from sites like this, books, conversations with other people, and so on.

BTW a random tip. I find it hard glancing at your code to see what arguments your function accepts in what order. That is why most people put function processing into its own section. Consider the following slightly modified version to see what I mean:

sub Send_Header { my %passed_args; @passed_args{'header', 'to', 'subject'} = @_; my $header_tmpl = HTML::Template->new( filename => 'header.tmpl' ); $header_tmpl->param( %passed_args, date => substr(scalar gmtime time, 0, 10), ); print $header_tmpl->output(); }
Isn't it easier there to glance at the function and see how it is supposed to be used? Now personally I would suggest putting everything in the template constructor if possible. Aim for having as few elements of control as possible. If you can do that then there is no need to bother naming temporaries:
sub Send_Header { my %passed_args; @passed_args{'header', 'to', 'subject'} = @_; print HTML::Template->new( filename => 'header.tmpl', date => substr(scalar gmtime time, 0, 10), %passed_args, )->output(); }
That method of chained method calls can be hard to read if you are not used to it, but think of it as being like a pipeline and you won't go too far wrong. Also it would be nicer if there wasn't a mix between the functionally written print, and the chain, but I don't find it too confusing.

And I would personally prefer to see a custom written date formatting function rather than the inlined version of gmtime which someone has to run to see what it does...

And so it goes...


In reply to Re (tilly) 1: Too Many Ways To Do It by tilly
in thread Too Many Ways To Do It by George_Sherston

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.