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

I have mutilate files in a folder and i read the lines from the files and do some execution on it and i use a loop to read the file. I want to know is there anyway to mark a file as unreadable for any reason if the file was not readable for example if its corrupted or if its a binary file so that if i run the programme again it will skip the file.
  • Comment on mark unreadable file so a loop does not read the file again

Replies are listed 'Best First'.
Re: mark unreadable file so a loop does not read the file again
by GrandFather (Saint) on Dec 05, 2008 at 05:24 UTC

    Sounds like you need to keep a configuration file of some sort that contains a black list of files (files to ignore). There are many modules that you could use for this purpose, but my current favourite is YAML.


    Perl's payment curve coincides with its learning curve.
Re: mark unreadable file so a loop does not read the file again
by nagalenoj (Friar) on Dec 05, 2008 at 06:06 UTC

    You have to be careful before changing the characteristics(binary, unreadable,..,) of a file. Because, it is going to affect you when you access the file for some other purpose.

    It is better to log the read file names in a separate file(log) and check the existence of file name in the file(log) before reading the files.

Re: mark unreadable file so a loop does not read the file again
by cdarke (Prior) on Dec 05, 2008 at 10:27 UTC
    There are many solutions. On Windows you could tag each bad file with an Additional Data Stream, that's just the main filename with :something tagged on the end.

    Simpler, and more portable, have a directory (called badfiles?), which is otherwise empty, and just create an empty file within it named the same as the bad file. The test to see if the bad file is there is a simple -e.

    To avoid using a binary file use the -B test, that is not 100% accurate but works most of the time. If the file is genuinely corrupt then you might want to chmod 000 so no one can use it.
Re: mark unreadable file so a loop does not read the file again
by SuicideJunkie (Vicar) on Dec 05, 2008 at 14:54 UTC
    My first thought was "this sounds like a job for a hash".
    next if exists( $filesToSkip{$filename} );
    The retention between runs requirement just means that you need to save the hash to a file and load it back on startup:
    Try Storable for that.
Re: mark unreadable file so a loop does not read the file again
by jdporter (Paladin) on Dec 05, 2008 at 14:20 UTC

    Depending on your approach, the possibilities could depend substantially on which operating system you're using.
    On Windows, I'd say you could try using the Archive bit.

    Between the mind which plans and the hands which build, there must be a mediator... and this mediator must be the heart.