Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Temp file strategy

by blazar (Canon)
on Sep 15, 2005 at 16:54 UTC ( #492328=note: print w/replies, xml ) Need Help??

in reply to Temp file strategy

A "cheap" solution that has not been mentioned yet, relies on an open feature that IMHO should be better known:
open my $temp, '+>', undef or die $!;

Replies are listed 'Best First'.
Re^2: Temp file strategy
by chb (Deacon) on Sep 19, 2005 at 06:55 UTC
    This is an interesting feature, but how can a user download such a file? If I understand perldoc -f open correctly, this syntax gives you a filehandle to an anonymous temporary file. Will you need some sort of streaming or some webserver trickery to let the user access this file from outside the perl script?
      Indeed. But it depends on the OS you're under: I'm not really sure, but I think that Windows doesn't support real anonymous files, so the temporary file that you can see should still be there somewhere.

      Here I'm under Linux and I get

      $ strace -e open perl -e 'open $f, "+>", undef' 2>&1 | tail -n 1 open("/tmp/PerlIO_vfNALU", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600) = +3
      but of course it is soon deleted:
      $ perl -le 'open $f, "+>", undef; print readlink "/proc/self/fd/" . fileno $f' /tmp/PerlIO_vJg2Uf (deleted)
      $ perl -le 'open $f, "+>", undef; print readlink "/proc/self/fd/" . fileno $f' /tmp/.nfs0004821b00000353
      if run on a machine where /tmp is mounted under nfs.)

      Whatever, all this is at best fragile and tricky. This interesting open feature is best suited for a file to write stuff into, to recover it later. For your application any of the other suggestions you got would be probably preferable.

      I just mentioned this temp file strategy option because IMHO it would deserve to be better known.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://492328]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2019-10-22 09:36 GMT
Find Nodes?
    Voting Booth?