Linux 无法取消链接
我对这里的Linux 无法取消链接,linux,perl,unlink,Linux,Perl,Unlink,我对这里的unlink()完全感到困惑: my $file = "\"/home/user/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html\""; unlink($file) or warn "Could not unlink $file: $!"; 会扔 Could not unlink "/home/user/Documents/Programming/Perl/extracted/
unlink()
完全感到困惑:
my $file = "\"/home/user/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html\"";
unlink($file) or warn "Could not unlink $file: $!";
会扔
Could not unlink "/home/user/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html": No such file or directory
当文件实际存在时:
$ ls -l "/home/user/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html"
-rw-rw-r-- 1 user user 413 Mar 25 13:41 /home/user/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html
编辑:我也试过:
my $file = "/home/user/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html";
my $file = '/home/user/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html';
my $file = "\'/home/user/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html\'";
同样的错误
编辑2:根据choroba的要求进行更多测试
使用-f
测试文件是否存在返回false
以下是真实文件名的hextump:
$ ls "/home/yasin/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html" | hexdump -c
0000000 / h o m e / y a s i n / D o c u
0000010 m e n t s / P r o g r a m m i n
0000020 g / P e r l / e x t r a c t e d
0000030 / P r u e b a c o n f o r m
0000040 a t e o H T M L / m s g - 2 5
0000050 7 5 - 4 . h t m l \n
000005a
文件名不包含双引号。不要将它们包含在变量的值中
my $file = '/home/user/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html';
unlink $file or warn "Could not unlink $file: $!";
文件名不包含双引号。不要将它们包含在变量的值中
my $file = '/home/user/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html';
unlink $file or warn "Could not unlink $file: $!";
这相当于做某事
rm "\"/home/.../msg-2575-4.html\""
显然,正确的shell命令是
rm "/home/.../msg-2575-4.html"
所以你想要
my $file = "/home/.../msg-2575-4.html";
unlink($file)
或
如果第二个rm
命令起作用,那么Perl命令也起作用
这相当于做某事
rm "\"/home/.../msg-2575-4.html\""
显然,正确的shell命令是
rm "/home/.../msg-2575-4.html"
所以你想要
my $file = "/home/.../msg-2575-4.html";
unlink($file)
或
如果第二个
rm
命令起作用,那么Perl命令也起作用。引号是因为路径上有空格。我已经尝试过各种各样的引用。它不工作,同样的错误…@m0skit0:这是Perl,不是shell。您不需要引用空格。谢谢。正如我上面所说的:同样的错误。@m0skit0:你能用-f
测试文件是否真的存在吗?你能通过管道将ls
的输出传输到一个hexdump以验证没有其他奇怪的字符(标签等)吗?我已经更新了我的问题。看起来没有奇怪的角色。这也是一个简化的测试。我使用的实际文件名是由Perl的readdir()
返回的,因此我想这也会返回奇怪的字符,但它也失败了。引号是因为路径上有空格。我已经尝试过各种各样的引用。它不工作,同样的错误…@m0skit0:这是Perl,不是shell。您不需要引用空格。谢谢。正如我上面所说的:同样的错误。@m0skit0:你能用-f
测试文件是否真的存在吗?你能通过管道将ls
的输出传输到一个hexdump以验证没有其他奇怪的字符(标签等)吗?我已经更新了我的问题。看起来没有奇怪的角色。这也是一个简化的测试。我使用的实际文件名是由Perl的readdir()
返回的,因此我想这也会返回奇怪的字符,但它也会失败。谢谢,但正如我在问题中所说的,这也不起作用:)那么rm
(或者ls
,如果它是一个文件未找到的问题)。这不是Perl的问题。此外,“不要工作”也是无用的说法。您费心打印错误消息,为什么不把它给我们。@m0skit0,如果第二个rm命令有效,我将重复,Perl命令也有效。如果那句话不是真的,那么你没有告诉我们的其他事情就不同了;打印(转储程序($file))并对从readdir
生成的字符串执行相同的操作。无需发布。问题一直是我的错。我忘记了文件是由另一个脚本生成的,并且文件名是动态的(使用时间戳),所以在我的测试中,以前的硬编码文件名不再存在。感谢您的时间和耐心:)谢谢,但正如我在问题中已经指出的,这也不起作用:)那么rm
(或者ls
,如果是文件未找到的问题)。这不是Perl的问题。此外,“不要工作”也是无用的说法。您费心打印错误消息,为什么不把它给我们。@m0skit0,如果第二个rm命令有效,我将重复,Perl命令也有效。如果那句话不是真的,那么你没有告诉我们的其他事情就不同了;打印(转储程序($file))并对从readdir
生成的字符串执行相同的操作。无需发布。问题一直是我的错。我忘记了文件是由另一个脚本生成的,并且文件名是动态的(使用时间戳),所以在我的测试中,以前的硬编码文件名不再存在。感谢您的时间和耐心:)