Temporary filename

Temporary filename

am 07.09.2007 18:25:02 von Bill H

I have seen the FAQ on creating a temporary filename, but is there
anyway of make them self-delete after a certain time period (probably
not, but you guys have done some amazing stuff with perl)?

Bill H

Re: Temporary filename

am 07.09.2007 18:34:47 von Paul Lalli

On Sep 7, 12:25 pm, Bill H wrote:
> I have seen the FAQ on creating a temporary filename, but is
> there anyway of make them self-delete after a certain time
> period (probably not, but you guys have done some amazing stuff
> with perl)?

What about alarm() and $SIG{ALRM} ?

perldoc -f alarm
perldoc perlipc

Paul Lalli

Re: Temporary filename

am 07.09.2007 19:35:39 von Martijn Lievaart

On Fri, 07 Sep 2007 09:25:02 -0700, Bill H wrote:

> I have seen the FAQ on creating a temporary filename, but is there
> anyway of make them self-delete after a certain time period (probably
> not, but you guys have done some amazing stuff with perl)?

On *nix, delete the directory entry but keep the filehandle. The file
will be gone once you close the filehandle.

M4

Re: Temporary filename

am 07.09.2007 19:43:47 von Ben Morrow

Quoth Bill H :
> I have seen the FAQ on creating a temporary filename, but is there
> anyway of make them self-delete after a certain time period (probably
> not, but you guys have done some amazing stuff with perl)?

If you just want to make sure the file goes away when you've finished
with it, you can use the File::Temp module. Otherwise, please give more
details on what you are trying to accomplish; unless

system qq{sleep 5 && rm -f "$file" &};

does what you want. In general you will need to have a process hanging
around to remove the file for you.

Ben

Re: Temporary filename

am 07.09.2007 21:12:46 von Bill H

On Sep 7, 1:43 pm, Ben Morrow wrote:
> Quoth Bill H :
>
> > I have seen the FAQ on creating a temporary filename, but is there
> > anyway of make them self-delete after a certain time period (probably
> > not, but you guys have done some amazing stuff with perl)?
>
> If you just want to make sure the file goes away when you've finished
> with it, you can use the File::Temp module. Otherwise, please give more
> details on what you are trying to accomplish; unless
>
> system qq{sleep 5 && rm -f "$file" &};
>
> does what you want. In general you will need to have a process hanging
> around to remove the file for you.
>
> Ben

I was having a hard time figuring out how to explain it, and realized
that what I need to do has to be done in the software, ie creating the
temporary file (a jpg image) and then deleting that one and creating a
new one (with a new name) when things change, while keeping track of
what file is "current" in a different file (in this case an XML). I
was hoping to have some way of having the old, replaced, unused files
(with obsolete filenames) "go away" on their own but I suppose a file
system hasn't progressed to the point of being able to use it like
memory where you "allocate" a block of memory and when done using it
you can "unallocate" it and it "goes away".

Bill H

Re: Temporary filename

am 08.09.2007 00:11:45 von Ben Morrow

Quoth Bill H :
> On Sep 7, 1:43 pm, Ben Morrow wrote:
> > Quoth Bill H :
> >
> > > I have seen the FAQ on creating a temporary filename, but is there
> > > anyway of make them self-delete after a certain time period (probably
> > > not, but you guys have done some amazing stuff with perl)?
> >
> > If you just want to make sure the file goes away when you've finished
> > with it, you can use the File::Temp module. Otherwise, please give more
> > details on what you are trying to accomplish; unless
> >
> > system qq{sleep 5 && rm -f "$file" &};
> >
> > does what you want. In general you will need to have a process hanging
> > around to remove the file for you.
>
> I was having a hard time figuring out how to explain it, and realized
> that what I need to do has to be done in the software,

Is 'the software' your Perl program or some other program it is trying
to cooperate with?

> ie creating the temporary file (a jpg image) and then deleting that
> one and creating a new one (with a new name) when things change, while
> keeping track of what file is "current" in a different file (in this
> case an XML).

Note that you don't have to change the name: you could simply overwrite
the old file.

> I was hoping to have some way of having the old, replaced, unused
> files (with obsolete filenames) "go away" on their own but I suppose a
> file system hasn't progressed to the point of being able to use it
> like memory where you "allocate" a block of memory and when done using
> it you can "unallocate" it and it "goes away".

Err... yes, it has, it's just 'free' is spelled 'unlink' (and you can't
create dangling pointers) :).

If you want any useful help you will need to start from the beginning
and explain what you're doing and why it's not working, preferably with
(short!) examples of pieces of code that aren't doing what you want.

Ben

Re: Temporary filename

am 08.09.2007 01:23:02 von Spiros Denaxas

On Sep 7, 5:25 pm, Bill H wrote:
> I have seen the FAQ on creating a temporary filename, but is there
> anyway of make them self-delete after a certain time period (probably
> not, but you guys have done some amazing stuff with perl)?
>
> Bill H

Check out File::Temp, i think it can do what you are after.
http://search.cpan.org/dist/File-Temp/

Spiros

Re: Temporary filename

am 08.09.2007 06:27:00 von Joe Smith

Bill H wrote:
> temporary file (a jpg image) and then deleting that one and creating a
> new one (with a new name) when things change,

Here's how I did it at a previous job:

my $img_file = "WCOM-stock-price.gif";
my $mtime = (stat $img_file)[9]; # Changes if file was changed.
print qq(\n);

Whenever the stock price changed, the HTML being presented to the
browser would be slightly different, encouraging browsers to forget
about the cached version and fetch the new data.

-Joe