Hello,

there are more than one ways to do it...

1. Call the programm with a parameterlist where the last is the filename you are looking for and remove this name before starting find with my $filename = pop(@ARGV); and then compare each found filename with $filename

2. Use named parameters, e.g. with the Getopt::* - modules (e.g Getopt::Long) 3. Use named parameters and care for them by yourself, e.g.

scriptname.pl --dir="/dir1/sdir1" --dir="/dir2/sdir2" --file="thisfile +.txt"
I don't know if there are modules that handle this case. If not, you could do it like the following:
my $params = &GetParameters(); my @dirs = @{ $params->{dir} }; my @file = @{ $params->{file} }; # and so on sub GetParameters { my @allowedParams = qw(file dir); die &PrintUsage() unless @ARGV; my $params = {}; # shell contain parameters foreach (@ARGV){ my ($key, $val) = split(/\=/, $_, 2); # split up by the first = # test if $key is a valid parameter unless ($key =~ s/^\-\-//) { # must start with -- die "Error: invalid param $key\n"; } unless ( grep {lc($key) eq lc($_)} @allowedParams){ die "Error: param $key not allowed\n"; } # maybe do some checks if $val is existing .... # add param to hashreference $params push (@{ $params->{$key} }, $val); } # for return ($params); } # GetParameters
But before you use this code (which I haven't tested), better look if there's a module on CPAN that solves this problem.

Btw: i think programming with use strict; and use warnings; might be a very good idea, because it is much easier to find "silly" and "not-so-silly" errors that way

Best regards,
perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"


In reply to Re: File Find by strat
in thread File Find by oaklander

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.