balajinagaraju has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using File::Find from a function.
by vinoth.ree (Monsignor) on Mar 19, 2013 at 06:23 UTC | |
|
Re: Using File::Find from a function.
by Anonymous Monk on Mar 19, 2013 at 06:48 UTC | |
by balajinagaraju (Sexton) on Mar 19, 2013 at 09:13 UTC |