Some more comments for you:

I would move "use File::Basename;" outside of the subroutine and put it near the top of the module or program. I don't think the effect of the "use" is local to just the subroutine and calling it repeatedly doesn't make sense. This is not like C where function declarations would go at beginning of the sub. use causes the code of the module to be executed. Of course since you didn't even use this module in the code, you could just delete this statement.

If I have a single arg, or in an object to get the object ref, I use shift. Otherwise I use: my ($dir, $what) = @_;. In Perl 5.10 you can use the new //= operator, which tests for "definedness", $what //= '*';.

I would rethink the error conditions. You return a null hash if any of the mdcalc's produce a null string result, but its not clear that any sort of warning or error output will be available to see which file that happened upon. Some sort of croak, die, warn or whatever may be appropriate there.

The & is no longer needed in front of function calls. just: md5calc($file2md5) will suffice.

Adding extra concatenation operators in the print is unnecessary. print MD5OUT $md5 . " " . $file2md5 . "\n"; could be print MD5OUT "$md5 $file2md5\n";.

$file2md5 =~ s/$dir\///; this is just $f.

A list of files like "a b c" in a single string is a weird way of doing that. The caller probably has these file names in an array, so use an array or ref to an array to pass these names, eliminating this split() stuff.


In reply to Re: Pass the arguments to the procedure in an easier way by Marshall
in thread Pass the arguments to the procedure in an easier way by Scottie

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.