I have code like below. If I open the file $File::Find::name
(in this case it is ./tmp/tmp.h
) in my search
function (called by File::Find::find
), it says "cannot open the file ./tmp/tmp.h reason = No such file or directory at temp.pl line 36, line 98."
If I open the file directly in another fuction function, I am able open the file. Can somebody tell me the reason for this behavior? I am using activeperl on Windows and the version is 5.6.1.
use warnings;
use strict;
use File::Find;
sub search
{
return unless($File::Find::name =~ /\.h\s*$/);
open (FH,"<", "$File::Find::name") or die "cannot open the file $File::Find::name reason = $!";
print "open success $File::Find::name\n";
close FH;
}
sub fun
{
open (FH,"<", "./tmp/tmp.h") or die "cannot open the file ./tmp/tmp.h reason = $!";
print "open success ./tmp/tmp.h\n";
close FH;
}
find(\&search,".") ;