Other online diaries:
Martijn van Oosterhout,
Linux Weekly News,
Planet Linux Australia,
Archive by month:
Mon, 28 Mar 2005
Faster directory reading - 20:13
I suppose if Jeremy is
to some of Mikal's perl
it will not hurt to also.
Mikal asks if there is a
faster way to read a directory than using open and ls and stuff. This reminds
me of a buttload entry a bit
<Schwern> Are we using perl to generate a shell script?
<Schwern> Its like building a bridge across a canyon so you can tie
a rope and cross with that.
Anyway with perl and TMTOWTDI the answer is yes you can do this
faster. Michael, the simplest way is simply using opendir and readdir, if you
look at the documentation in "perldoc -f readdir" you can probably see an
example. Using native perl is always going to be faster than launching a
separate shell (which you probably realise, explaining why you wondered if
there is some faster way).
Of course looking at the things you have been asking today I wonder if the
perl module File::Find may help you out with doing some of the stuff you need.