I have a piece of Perl code for searchnig a directory and display the contents of that directory, if match is found. The code is given below:
$test_case_directory = "/home/sait11/Desktop/SaLT/Data_Base/Test_Case";
$xml_file_name = "sample.xml"
$file_search_return = file_search($xml_file_name);
print "file search return::$file_search_return\n";
sub file_search
{
opendir (DIR, $test_case_directory) or die "\n\tFailed to open directory that contains the test case xml files\n\n";
print "xml_file_name in sub routines:: $xml_file_name\n";
$dirs_found = grep { /^$xml_file_name/i } readdir DIR;
print "Files in the directory are dirs_found :: $dirs_found\n";
closedir (DIR);
return $dirs_found;
}
Output is,
xml_file_name in sub routines:: sample.xml
Files in the directory are dirs_found :: 1
file search return::1
It is not returning the file name found. Instead it returns the number 1 always.
I don't know why it is not returning the file name called sample.xml
present in the directory.