I'm totally puzzled with unlink()
here:
my $file = "\"/home/user/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html\"";
unlink($file) or warn "Could not unlink $file: $!";
will throw
Could not unlink "/home/user/Documents/Programming/Perl/extracted/Prueba con formateo HTML/msg-2575-4.html": No such file or directory
while the file actually exists:
$ 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
EDIT: I also tried:
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\'";
Same error.
EDIT2: more tests as required by choroba
Testing the file existence with -f
returns false.
Here's a hexdump of the real file name:
$ 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/.../msg-2575-4.html\"";
unlink($file)
is the equivalent of doing
rm "\"/home/.../msg-2575-4.html\""
Obviously, the correct shell command is
rm "/home/.../msg-2575-4.html"
so you want
my $file = "/home/.../msg-2575-4.html";
unlink($file)
or
my $file = '/home/.../msg-2575-4.html';
unlink($file)
If that second rm
command works, so does that Perl command.