Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts

    unlink - must be rusty

    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

    Code:
    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



    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,871
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Try:
    Code:
    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: $!";
    }

  • #3
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    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).

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




    Code:
    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
    Code:
    Usage: POSIX::remove(filename) at images_remove.pl line 159
    bazz
    Last edited by bazz; 07-20-2010 at 03:42 PM.
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,871
    Thanks
    2
    Thanked 164 Times in 159 Posts
    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".

  • #5
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    strange thing to is that the error was the same whether I had use POSIX; declared or not.

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •