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

I have a perl/gtk program and which makes use of the File::Util module. The problem is that it abruptly terminates when using the list_dir method on a directory where you do not have permissions.

--- Error ---

The system returned this error: »Permission denied«

I would like to trap the error and then bypass the directory/directories where I do not have permissions

Any recommendations on how to manage this?

Replies are listed 'Best First'.
Re: File::Util list_dir question
by holli (Abbot) on Nov 30, 2009 at 15:39 UTC
    straight from the docs:
    Flags accepted by new()

    --fatals-as-status

    Directive to instruct the new File::Util object that when any call to one of its methods results in a fatal error that it should return undef instead of the value(s) that would normally be returned by the call.
    Don't take this as a RTFM please, it took me a while to find about that too.


    holli

    You can lead your users to water, but alas, you cannot drown them.

      Thanks very much holli.

      I passed right by it and should have been more attentive...but it is there so I'll call it a lowercase rtfm.

        No biggie. The interface of File::Util is non intuitive. Normally a method fatals (dies) or returns some kind of false on failure. File::Util does nothing of this.

        It uses a halb baked homegrown error handler that, believe it or not, calls exit on a 'fatal' error (like not being able to recurse into a directory).
        That's why you cannot trap it with eval nor with try{}catch{} (at least until said flag is specified).


        holli

        You can lead your users to water, but alas, you cannot drown them.
Re: File::Util list_dir question
by stefbv (Priest) on Nov 30, 2009 at 14:45 UTC
    Some code would have been helpful, but without it my answer is: use eval around the code.