Hi Monks!

I have a procedure whose task is to count checksums for files that are a input argument in subroutine. Argument can be:
- All files ('*') in a directory ($DIR).
- Files with the extensions, for example: '*.foo *.bar *.pl *.pm'
- Files with names beginning, for example: 'FOO* bar*'

--------------8<-------------- sub md5files { use File::Basename; my $dir = $_[0]; # where the files are (must be a di +rect path from root /) my $what = $_[1] || '*'; # what files, default = '*' (all fi +les) my $md5file = "$dir/checksums.md5"; my %hash_md5; my @t = split(/ /, $what); open (MD5OUT, '>', $md5file ) or die "Err: $!"; foreach my $f (@t) { foreach my $file2md5 (<$dir/$f>) { next if "$file2md5" eq "$md5file"; my $md5 = &md5calc($file2md5); if($md5 ne "") { $file2md5 =~ s/$dir\///; print MD5OUT $md5 . " " . $file2md5 . "\n"; $hash_md5{$md5} = $file2md5; } else { return ""; } } } close MD5OUT; return %hash_md5; } --------------8<--------------

Above sub can be called as follows:
my $DIR = '/tmp';
my %md5hash = &md5files($DIR);
my %md5hash = &md5files($DIR,'FOO* bar*');
my %md5hash = &md5files($DIR,'*.foo *.bar *.pl *.pm');

Is it possible to simplify my procedure? Could it be more perlish?

Thanks in advance.

Best regards,
--
Scottie


In reply to 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.