You should use the Perl functions unlink() to delete a file and copy() (From the File::Copy module) to copy a file. | [reply] [d/l] [select] |
wow... showing the inexperience huh... hehe thanks :)
| [reply] |
And so appeared, perlmonks, to help us all out. Everybody is inexperienced at some subset of every language.
| [reply] |
cbro was spot on. Also, concerning your use of system... This is probably what you want/mean:
system(@args) == 0 || die "Failed to delete: $!";
See system concerning return value.
cp
----
"Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."
| [reply] [d/l] |
Of course in this case unlink($filename) would be better.
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature | [reply] [d/l] [select] |
@args = ( 'sh', '-c', "erase $filename" );
and this is important in case you want to quote arguments to be given to the internal command. But going very far down that road gets rather complicated quickly so I'll leave that for another time.
The reason your code works is because, in Win32,
system(@args) is (quite unfortunately) exactly the same as
system("@args") because Win32 only deals with command lines while Unix (and C) want to deal with lists of command arguments. This can make getting the proper arguments passed in quite difficult, especially since it also means that each program parses its own command line and so you often have to prepare/quote your arguments different for different commands.
Also note that Perl will do the "cmd /c" trick for you automatically (if it can't find a "erase.*" executable in your PATH).
- tye | [reply] [d/l] [select] |
FYI, Perl already does that for you!
C:\>set prom
PROMPT=$P$G
C:\>perl -e "system('set prom')"
PROMPT=$P$G
C:\>perl -e "system('set.exe prom')"
Environment variable .exe not defined
That last example is in there to show you that is isn't running some SET.EXE but is really running cmd.exe and passing it the command "set prom".
- tye | [reply] [d/l] |