in reply to Problem with system ()

I find that when most people try to execute outside programs from Perl, a pure-Perl version is often as short or shorter. This is not to say there is no good use of executing outside programs, just that it's usually not.

In this case, as another poster mentioned, you can use glob and unlink:

unlink glob('C:\temp\*.audit');

So it shaved off a line of code and doesn't have the overhead or potential security risk of executing an outside program. I don't see a downside here, except maybe the time it took to RTM.

Update: Everyone needs to RTM. And that includes me. Problem with character escaping fixed, as per suggestions below.

----
Reinvent a rounder wheel.

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Problem with system ()
by Thelonius (Priest) on Mar 18, 2003 at 15:59 UTC
    This has a problem with backslashes:
    unlink glob("C:\temp\*.audit");
    Should be one of these:
    unlink glob("C:\\temp\\*.audit"); unlink glob('C:\temp\*.audit'); unlink glob("C:/temp/*.audit");
Re: Re: Problem with system ()
by Nkuvu (Priest) on Mar 18, 2003 at 16:06 UTC

    Careful -- you may get errors with this. You either need to single quote strings with \ or double your \. So you can change this to "C:\\temp\\*.audit" or 'C:\temp\*.audit' or (my preference) "C:/temp/*.audit"