The script works, but will only save the new file if I manually delete the old one.I can't get perl to delete it's own file from within perl.

It'd be nice if you supplied us with the error you get when you try, and not to forget, the method you try.

When I try to manually delete it, I get:
override rw-r--r-- www/admin for 1image.jpg?

Assuming that your http daemon runs under the user account "www", it looks like a simple unlink should do the trick. That user has write permissions, and should be able to delete the file it created too. You (as in: the user you try to remove the file with) seem to have enough permissions on the directory, but not on the file, hence the warning.

and as www/admin I can.

If you can `su` to user "www" and manually delete it, I see no problems why you can't delete the file (or overwrite it, what you probably want to begin with) from within your script.

I've never seen Image::Grab before, but try this little snippet and please return us the error message you might get (please note that this is almost taken verbatim from the POD):

use Image::Grab; $url = "http://wherever/you/snatch/your/image/from.jpg" $pic->url($url); $file = "/Library/WebServer/Documents/gcdata/".$id."image.jpg"; open(IMAGE, ">$image") || die "Can't open $image: $!"; print IMAGE $pic->image; close IMAGE;

And please check for some weird permissions on "/Library/WebServer/Documents/gcdata/". If, for some reason, you want to alter the permissions the file is saved under, you might want to check out umask too.

$cmd3 = "rm ".$imgfile."";

Please note that you included a ">" sign in $imgfile, which is probably nagging you here. Please don't use that in the filename, but in the open statement (as my example points out) and of course, use unlink instead of system("rm ...") ;)

HTH

--
b10m

All code is usually tested, but rarely trusted.

In reply to Re: Kill file that I created, and recreate by b10m
in thread Kill file that I created, and recreate by ecuguru

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.