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

1) Get rid of garbage like $_[0], $_1. Instead use shift():

sub do_stuff { my $dir = shift; my $pattern = shift; ...

... or list assignment if you want to keep @_ intact:

my ($dir, $pattern) = @_;

Do either of those as the *first* line(s) of your sub.

2) In general, your variable names are atrocious:

$what --> $pattern_str @t --> @patterns $f --> $pattern $file2md5 --> $fname

3) As an alternative to split() and looping, you could chdir($dir) and then glob($pattern_str).

4) What do you think the quote marks do here:

"$file2md5"

5) Don't use bareword filehandles. Use a my() variable instead(which you can capitalize if you want to):

my $fname_out = 'name.txt'; open my $OUTFILE, '>', $fname_out or die "Couldn't open $fname_out: $!"; #and then... print $OUTFILE "whatever";

In reply to Re: Pass the arguments to the procedure in an easier way by 7stud
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.