Lets start with some code:
my $handle = gensym; open $handle, ref ($file) ? ">&". fileno ($file) : ">" . $file and binmode ($handle) or goto &_drat;
This is from Archive::Tar, around line 750, for those who like to read along. This has been my absolute arch nemesis in this project. It wants a steenkin' file. And it will not accept anything but a file. Some of you may have read Self Extracting Archives with Perl (almost) a while ago. I had at the time abandoned using Archive::Tar. However, I am doing a similar thing now and I must use tar. So I'm going over my code again, and updating it with the knowledge I've learned since then, and I switched to IO::String from IO::Scalar due to this bit in the IO::Scalar pod: and this bit from the Archive::Tar pod: So in theory, IO::String allows me to create a pseudofile in memory that I can then print stuff to as if it were a file. My hope was that Archive::Tar wouldn't know any better, and would happily print to it, and I could then steal its tarball and do cool stuff to it (like MIME::Base64 or Convert::UU or Compress::Gzip, et cetera), followed by even more cool stuff (like Mail::Mailer, among other things)

Mmmmkay, let's look at some errors.

is gleaned from the following code: So that's kind of sucky. But I found out that the FETCH thing I'm looking for is over in perldoc perltie, and it seems like a real pain in the ass. So this all boils down to one thing. I have a module that wants to write to a filehandle. But I dont want to write to the disk at all. I am just going to pass it to something else, and I dont see why I should have to write out a file and read it back in. That just seems stupid. But all the seemingly close-enough-to-be-useful methods are a) very complicated or b) not the solution.

If Larry were to fix this for me today, it would be thusly:

open TRICKERY, \$stringamabob;
Which 'works', but actually doesnt. (try it and see).

I guess the other solution would be to steal Archive::Tar's data. That doesnt seem particularly elegant, and I'd rather have a perl solution to this.

Finally, since this was rather information-rich, I pondered putting it in Meditations. However, I didnt really produce anything worth meditating on, so it resides in SoPW for now. Feel free to edit if if you feel the urge.

whiiiiiiiiine,
brother dep.

--
Laziness, Impatience, Hubris, and Generosity.


In reply to Tricking modules into thinking scalars are globs. (code) by deprecated

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.