in reply to Re: perl glob and an exception
in thread perl glob and an exception

eval can catch runtime error, it does not work for a case below:

user@host: mkdir ~/test

user@host: touch ~/test/file1.txt

user@host: chmod 000 ~/test

### perl code my $dir = '/home/user/test'; my @files = eval { glob("$dir/*.txt") }; print "$@" if $@; # here is no runtime error print Dumper(\@files); # shows an empty list

Replies are listed 'Best First'.
Re^3: perl glob and an exception
by Corion (Patriarch) on Sep 25, 2015 at 09:53 UTC

    So, what is your question? If there is no exception, you can't catch it either.

    Maybe you wanted to ask how glob can tell you whether there was a problem with one of the filespecs?

    For that, you will have to use opendir and readdir instead, and check for errors yourself.

      You are right, Sir :) The question was about - how glob can tell me if there is an issue with a file system. E.g. I don't have a permissions etc.
        :)see glob does what it does, if you want something different, make your own sub glob

        How about combining glob with grep?

        my @readable = grep { -r } glob "*.txt";

        OK, so you'll have to implement a bunch of tests if you want check multiple things, but that's because glob - for efficiency reasons - does nothing other than read a directory (See: perldoc -X)