Hi, My requirement is to expose a perl function from our product to the users(other developers using our product) to find whether a file is present in a particular directory. For this the user calls my function with the Directory name and Filename as parameters. Internally in my function definition i need to handle the file finding part and i am using File::find for this purpose, just a snippet is below

use File::Find; my $dir = "C:\\Users\\Public\\ABCD\\Core\\sdk\\PAT"; find(\&myfile, $dir); sub myfile{ my $file = C:\\Users\\Public\\ABCD\\Core\\sdk\\PAT\pat.xml"; if(-e $file){ print "Exists"; } else{ print "Doesn't exits"; } }

In this example currently i am hardcoding the filename inside my myfile function but ideally it would be a parameter recieved from a function call, here 'Find' takes the function reference and the directory name as the parameter now how do i send the filename along with the function reference and directory name to the 'Find' method.

In short 1) The user calls myfunction(Directoryname , Filename) 2)Myfunction definition should invoke the 'Find' method with the default parameters as well as the Filename mentioned in the users call. How do i accomplish this?. Hopefully the problem is clear.


In reply to Using File::Find from a function. by balajinagaraju

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.