in reply to Pass the arguments to the procedure in an easier way

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.

Replies are listed 'Best First'.
Re^2: Pass the arguments to the procedure in an easier way
by 7stud (Deacon) on Jun 16, 2011 at 23:20 UTC
    $file2md5 =~ s/$dir\///; this is just $f.

    Also, you can use another delimiter for s/// so that you don't have to escape internal characters, e.g.

    s{$dir/}{}

    When you escape characters in a pattern, it makes the pattern hard to read.

    You also have to be aware that any characters in your dir name that are regex metacharacters, like a dot, braces, etc. need to be escaped to make perl recognize them as the literal characters rather than special regex characters. You can use quotemeta() on the string, which will escape any regex characters.