![]() |
|
Think about Loose Coupling | |
PerlMonks |
Tricking modules into thinking scalars are globs. (code)by deprecated (Priest) |
on May 08, 2001 at 03:58 UTC ( [id://78724]=perlquestion: print w/replies, xml ) | Need Help?? |
deprecated has asked for the wisdom of the Perl Monks concerning the following question:
Lets start with some code:
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: 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, --
Back to
Seekers of Perl Wisdom
|
|