At 11:47 Uhr -0400 10.06.2001, Chris Nandor wrote:
>At 19:50 +0200 2001.06.07, Thomas Wegner wrote:
>>Looking again at Dir.pm and remembering your reply concerning File::Copy, I
>>think we should really add the following to open()
>>
>>
>> sub open {
>> @_ == 2 or croak 'usage: $dh->open(DIRNAME)';
>> my ($dh, $dirname) = @_;
>> return undef
>> unless opendir($dh, $dirname);
>> $dirname = ':' . $dirname if ( ($^O eq 'MacOS') && ($dirname =~
>>/^[^:]+$/) ); # added
>> ${*$dh}{io_dir_path} = $dirname;
>> }
>> 1;
>> }
>>
>>
>>
>>to avoid that "dirname in the current directory" trap. Do you agree?
>
>Hm. Can you give an example of when it is required to have this? I am
>having trouble right now thinking of one.
>
Yes. In case someone uses the interface to reading directories via a tied HASH. Let's
say, our cwd is ":perl:t:". Now, if the user tries something like the following:
#! perl -w
use IO::Dir;
tie %dir, IO::Dir, "lib"; # opendir (DH, "lib") works
# The keys of the HASH will be the names of the entries in the directory.
# Reading a value from the hash will be the result of calling File::stat::lstat
(FETCH).
$file_size = $dir{'complex.t'}->size;
print "file_size= $file_size bytes\n";
that will fail without the above patch, because internally, a lstat("lib:complex.t");
is done instead of the correct lstat(":lib:complex.t"); -- note the leading ':'. The
same is true for other methods, too.
Does that convince you? ;-)
Best regards,
--Thomas
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com