unlink
LIST
This function deletes a list of files.[
11
]
If
LIST
is omitted, it unlinks the file given in
$_
.
The function returns the number of files successfully deleted.
Some sample commands:
[11] Actually, under UNIX, it removes the directory entries that refer to the real files. Since a file may be referenced (linked) from more than one directory, the file isn't actually removed until the last reference to it is removed.
$cnt = unlink 'a', 'b', 'c'; unlink @goners; unlink <*.bak>;
Note that unlink will not delete directories unless you are superuser and the -U flag is supplied to Perl. Even if these conditions are met, be warned that unlinking a directory can inflict Serious Damage on your filesystem. Use rmdir instead.
Here's a very simple rm command with very simple error checking:
#!/usr/bin/perl
@cannot = grep {not unlink} @ARGV;
die "0ドル: could not unlink @cannot\n" if @cannot;
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ]