Win has asked for the wisdom of the Perl Monks concerning the following question:

I have a Perl program that regularly checks for the presence of a new file in a directory held on a network drive. This program works well until the network drive is temporally unavailable. I would like a method that will somehow check to see if the network drive is available first and then check for the file. I want the program to continue running without throwing up an error message. It has been suggested that I look up the following: IO::Socket's is_connected and IO::Select's can_read, can_write, and has_exception
while(1) { # Check for presence of file here sleep 5; }
Enlightenment welcomed.

Replies are listed 'Best First'.
Re: Checking for the availability of network drive
by Anonymous Monk on Mar 06, 2009 at 11:03 UTC
Re: Checking for the availability of network drive
by ig (Vicar) on Mar 06, 2009 at 12:31 UTC

    Would it be sufficient to check that the directory exists?

    while(1) { if( -d $directory) { # Check for presence of file here } sleep 5; }

    Whatever test you do before you check for a new file, there is the possibility that access to the network drive is lost after you confirm that it is available but before you check for the new file, so your check for the new file should be written to handle the errors that might result. If it is, there may not be much advantage in checking that the network drive is available first.

Re: Checking for the availability of network drive
by Bloodnok (Vicar) on Mar 06, 2009 at 13:00 UTC
    I infer from the use of ...network drive that the context is Windoze - in which case I vaguely remember that the net command can be used to ascertain the availability of a network drive (see Re: Checking status of Network Mapped Drives).

    A user level that continues to overstate my experience :-))