Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Is there a way to open a memory file with binmode :raw?

by nikosv (Deacon)
on Oct 12, 2015 at 11:15 UTC ( [id://1144513]=note: print w/replies, xml ) Need Help??


in reply to Is there a way to open a memory file with binmode :raw?

You might be interested in perl has built-in temp files , a subtle way of creating temporary filehandles

Replies are listed 'Best First'.
Re^2: Is there a way to open a memory file with binmode :raw?
by stevieb (Canon) on Oct 12, 2015 at 15:27 UTC

    That is genius! Thank you so much for this :)

    I appreciate everyone's patience with me on this over the last month or so. Digging through all the docs was informative, but just a tad overwhelming trying to piece it all together which led to confusion.

    When it was pointed out that a scalar ref is NOT a file and the two are treated in different ways helped a lot.

    In this round, my goal was an anonymous temp file for which I had gone on to use File::Temp which I felt was a bit heavy-handed. I'm very surprised I never came across the link you shared in my travels.

    Cheers everyone,

    -stevieb

      Yeah, but that way of creating temporary files doesn't even honor $ENV{TMPDIR} (at least in some configurations), which makes it one of the worst ways to make temporary files in Perl in my book. I was rather shocked when I discovered such in the Perl source code (trying to figure out why Plack temporary files were being put into the wrong directory).

      - tye        

        trying to figure out why Plack temporary files were being put into the wrong directory

        On recent linux system you can find out the original location of the deleted file by examining /proc:

        qwurx [shmem] ~> perl open $fh, "+>", undef or die "Can't create anonymous storage: $!"; $file = "/proc/$$/fd/" . fileno $fh; print "$file => ", readlink( $file ), $/; __END__ /proc/26628/fd/3 => /tmp/PerlIO_eVAtFg (deleted)

        On systems which lack /proc/$$/fd it can be quite annoying to find out, specially when the file system is full and a process is just sitting around in IOWAIT. In this condition there's a difference between disk usage of device and file system. Found that on an old Solaris server running a program which employed this trick: create file, get handle, unlink. Took me some time to find out.

        perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-03-29 11:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found