Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

A minor quibble with the way you generate timestamps (in the LocalTime subroutine).

  • I don't like little subroutines that call print themselves. I prefer to return a string, and have the parent code call print. This lets you fold the call into a list of other things that are also passed to print. One of these days you'll want to fetch what LocalTime produces, but not have it print out anything. At that point you will be forced to either clone the code into a separate routine (and if you're smart you'll refactor the current routine in terms of that new routine), or else you'll have to pass an ugly mode param that tells the code whether it should print out or just return the string.
  • Use the ISO date format.
  • Call localtime once.

Putting it all together, you get something like:

sub timestamp { sprintf '%4d-%02d-%02d:%02d:%02d:%02d', sub{ $_[5]+1900, $_[4]+1, @_[reverse 0..3] }->(localtime) }

Note that this string is not perfect as it does not encode the local time zone. That, of course, is left as an exercise to the reader.


--
g r i n d e r

In reply to Re: Just Another Net::FTP Script by grinder
in thread (code) Just Another Net::FTP Script by ybiC

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (9)
    As of 2019-10-17 18:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?