develooper Front page | perl.perl5.porters | Postings from March 2006

Re: [perl #38790] readdir() only returns one result when used with

Thread Previous | Thread Next
Joshua ben Jore
March 23, 2006 09:10
Re: [perl #38790] readdir() only returns one result when used with
Message ID:
On 3/23/06, Rafael Garcia-Suarez <> wrote:
> Yitzchak Scott-Thoennes wrote:
> >
> > *Is* there any way to detect a failed list-context readdir()?
> Due to the iterative nature of readdir(), I doubt Fatal makes sense on
> it, from a language point of view. But strictly speaking, readdir()
> fails when there are no more entries to read, that is, by returning
> undef in scalar context, and an empty list in list context.
> > If not,
> > Fatal should continue to do what it is doing and the limitation should
> > be documented.
> That would be probably the best solution, but I wonder whether other
> builtins could cause the same kind of problems. A glance through the
> keyword list doesn't give other ideas. (Maybe select(), which returns -1
> on error.) There is also a minor inconsistency on some error values :
> some return 0 on error, some return undef (because 0 could be returned
> in case of success -- e.g. read()). So, short of harcoding all
> exceptions, there is no good fix.

So hardcode the exceptions. They're well established and limited.
Heck, for readdir(), if it returned an empty list/undef, why isn't $!
being examined to decide failure? It isn't that failure is
undetectable, it just isn't a case of looking at the return value
because any of empty/false/undef/-1/0 are possible as non-error

It could be considered the responsibility of a core module like Fatal
to handle all the various exceptional return values. I sure do. I also
see no reason why Fatal can't do the right thing. So why is it that
Fatal has to just document this as a limitation? It's possible for
Fatal to handle list context readdir, right? If so, it should.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About