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

comment on

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

My overall first impression is that this is pretty good code - subdivided into subroutines, nicely formatted, etc. It could be compacted / made mode "Perlish" in a couple places, but because TIMTOWTDI and the code is still clean and pretty easy to follow, I think it's fine the way it is. Just a few other issues / comments:

  • Most importantly, you're using the system function with a single argument and with user input (command-line arguments), which is vulnerable to injections, and you're not checking the calls for errors. See Calling External Commands More Safely for alternatives.
  • opendir also needs to be checked for errors, and it's better to use lexical file/dir handles, as in opendir(my $dh, $path) or die "$path: $!";.
  • Instead of your sub pad, you can use sprintf, as in sprintf("%02d", $num).
  • I would suggest you take the time to study Time::Piece and/or DateTime instead of the basic localtime stuff you're doing here, I think you'll be much happier in the long run.
  • You may also want to consider looking into Getopt::Long to pass arguments to the script instead of a plain list of arguments. IMHO it makes for much more readable script invocations.
  • Unless you're certain this will only ever be run on *NIX, you probably want to consider using a module for your filename manipulations. Personally I like Path::Class.
  • Now we're getting very nitpicky, but do you really need to provide two different date formats? For things like this I'd always stick to YYYY-MM-DD.

In reply to Re: looking for feedback on my first script by haukex
in thread looking for feedback on my first script by thirtySeven

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2021-08-05 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (44 votes). Check out past polls.

    Notices?