in reply to Re: switcher
in thread switcher

I know now that using File::Find would be better but I didn't know that when I wrote it so I used the right-tool-for-the-job ;-)

I changed the code to check the result of the opendir, would it have caused problems otherwise?

Why not shift it twice? Isn't that way faster than a grep?
A shift would just ++ the array's base pointer (in C) so it sounds logical to me to use this over grep, right?

Replies are listed 'Best First'.
Re: Re: Re: switcher
by repson (Chaplain) on Jan 01, 2001 at 17:58 UTC
    Yes, two perlfunc:shifts or a perlfunc:splice would be faster than grep, if you can absolutely always rely on . and .. being the first two items listed in a directory. Which you probably can't even if that is the case on your system.

    A false return on opendir means that the system had a reason why it couldn't read what was in the directory (probably no read permission for user, you can find out in $!). This means that the call to readdir would fail (I think it would be fatal under warnings and strict) or if the program tried to keep on going @fools would be empty, causing other problems.