in reply to perl glob and an exception

There is no need for glob to allow that. The standard mechanism is eval to catch exceptions in Perl.

Replies are listed 'Best First'.
Re^2: perl glob and an exception
by proxy-man (Initiate) on Sep 25, 2015 at 09:49 UTC
    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

      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.