Stefan Schmiedl
2/18/2005 9:20:00 AM
On Fri, 18 Feb 2005 05:09:29 +0900,
Mark Probert <probertm@acm.org> wrote:
>
> Hi ..
>
> In one of my apps, I am doing something like
>
> def clean
> f = `rm -f #{@datadir}/*.raw`
> end
>
> I could, just as easily do
>
> def clean
> Dir["#{@datadir}/*.raw"].each do |f| File.delete(f) end
> end
>
> Besides the portability aspect (does 'rm' exist on the box?), is one to be
> preferred to the other?
I'd go with the second one for everything that's not a one-time hack.
Depending on where the contents of @datadir originate, you might have
a security problem in the first method.
And you're starting an external process, which might become expensive,
if done often enough.
kind regards,
s.