Hi, I am using MIME::Parser to get the contents of an email passed to my script. It works fine like this:
my $input = \*STDIN; my $entity = $parser->parse($input);
But, I also want to keep a copy of the email exactly as it came in, before MIME::Parser does it's thing. However,
my $input = \*STDIN; my @copy = <$input>; open(COPY, ">copy.txt"); print COPY @copy; close COPY; my $entity = $parser->parse($input);
works fine for keeping the copy, but then there is nothing left for MIME::Parser to parse it seems. If I reverse the order, and parse it first, then there is nothing to print in my copy file.I gues STDIN is only good for one read? I tried makeing a copy of the reference, like
my $input = \*STDIN; my $copy = $input;
but that just makes another reference to the same data address I guess (which makes a lot of sense), because it is still only good for one read. I tried
my $input = \*STDIN; my @copy = <$input>; open (TMP, ">/tmp/copy.txt"); print TMP @copy; close(TMP); open($copy, "</tmp/copy.txt"); my $entity = $parser->parse($copy);
Which seems to make sense, but now MIME::Parse doesn't parse the $copy. If I print $copy; instead, I see that $copy does indeed contain a copy of the file, but I can't figure out why MIME::Parse will only parse it if it is the original. Anybody have any ideas?
Kbeen

In reply to Copy of a filehandle reference by Anonymous Monk

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.