Gunwant Singh wrote:
Hi all,

Hello,

I wrote a code that can search any file/folder on a PC given that you must give the file name with its extension. The code works fine. Any suggestions to make the code better or faster. Here is the code: --------------------------------------------------------------------------------------------
use strict;
use warnings;
use File::Find;

chdir('/');

There is really no need to change the current directory and if you must you should at least verify that chdir() worked correctly.

print "Enter the name of file/folder to search:\n";
my $fn=<STDIN>;
chomp($fn);
my $dir="\\";

Even on Windows you can use '/' instead of "\\". You may also need to provide a drive letter?

find(\&Wanted,$dir);


sub Wanted
{
if (($_ eq '.')||($_ eq '..')) { } else

Or more simply:

return if $_ eq '.' || $_ eq '..';

{
if ($_ eq $fn)
   {
   my $cwd = Win32::GetCwd();

The current directory can be found in $File::Find::dir.

   print "\nFile found in $cwd";

    print "File found in $File::Find::dir\n";

   }
}
}


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to