Fellow monks,

I'm tearing my hair out over this and I can't seem to find any answers.

I'm working on an app that is going to be reading from a file that will be made up of PGP encrypted e-mails. I'm going to read these in to an array so that I can process them one at a time.

My problem is that I can't figure out how to get MIME::Decoder to decode anything when I feed it a scalar - even if it's wrapped in a filehandle via IO::Wrap. It all works fine if I'm reading and writing to files, but I don't want to have to write every message to a file, decode it, write it back to a different file, then open and read it again to decode it.

When I run this through the debugger, $decoded is 1 - which according to the docs means it decoded something, but I'm at a loss how to make this work with just scalars.

I'm sure I've got a syntactial error in how I'm trying to do it, but I can't find any examples of what I'm trying to.

use strict; use Crypt::OpenPGP; use Data::Dumper; use MIME::Tools; use MIME::Decoder; use IO::Wrap; $|++; &decode; sub decode { my $decoder = new MIME::Decoder "quoted-printable"; my ($text, $outtext); { local $/; open(my $fh, '<', 'orders.txt') or die "Problem:$!"; $text = <$fh>; } $text = wraphandle($text); $outtext = wraphandle($outtext); my $decoded = $decoder->decode( $text, $outtext);

Any help would be appreciated!

Revolution. Today, 3 O'Clock. Meet behind the monkey bars.

In reply to Using scalar instead of file handle in MIME::Decoder by Popcorn Dave

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.