...

View Full Version : unlink - must be rusty



bazz
07-20-2010, 05:16 AM
Hi,

I am trying to remove an image from the server but I get the following error and can't seem to understand why, because I am not using POSIX. (though this error persists even if I do add use POSIX;)



my $img_file_path = '/var/www/vhosts/my_domain/subdomains/this/';

foreach my $image_for_removal (@images){
unlink $img_file_path/$image_for_removal or warn "Could not unlink $image_for_removal: $!";
}


errors with:
Usage: POSIX::remove(filename) at images_remove.pl line 159

:mad:

bazz

FishMonger
07-20-2010, 01:42 PM
Try:

my $img_file_path = '/var/www/vhosts/my_domain/subdomains/this';

foreach my $image_for_removal (@images){
unlink "$img_file_path/$image_for_removal" or warn "Could not unlink $image_for_removal: $!";
}

bazz
07-20-2010, 03:32 PM
Oops, FishMonger.

I had the double quotes in but forgot to show them in my OP.

Here is the actual failing code (with domainname changes only).


Got it :). my sub was named remove which must be a reserved word. Named it 'remove_image' and it all flies.






my $img_file_path = "/var/www/vhosts/mydomain.com/subdomains/cms/httpdocs/images/$business_id/Gallery";

foreach my $image_for_removal ( sort @images_for_removal ){


#delete from image_galleries where image_id = $image_for_removal
$sth1->execute($image_for_removal) or die "execute statement failed : $DBI::errstr\n";

# delete from images where id = $image_for_removal
$sth2->execute($image_for_removal) or die "execute statement failed : $DBI::errstr\n";


unlink "$img_file_path/$image_for_removal" or warn "Could not unlink $image_for_removal: $!";
}


Still gives the error


Usage: POSIX::remove(filename) at images_remove.pl line 159


bazz

FishMonger
07-20-2010, 07:44 PM
remove is subroutine which is defined in the POSIX module and is used exactly like the Perl's built-in unlink function.

Since you defined your own remove sub, I would have expected a compilation error on the lines of "subroutine remove redefined at line xxx".

bazz
07-20-2010, 08:23 PM
strange thing to is that the error was the same whether I had use POSIX; declared or not.

bazz



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum