Per the open manpage, I am attempting to open a filehandle to a variable in memory and I am unable to read the variable. My code looks like this:

open(MESSAGE, "+>>", "\$message") or die "no message $!"; open(WHOM, ">>", "&=MESSAGE") or die "no whom $!"; open (WHAT, ">>", "&=MESSAGE") or die "no what $!";

after which much is written to the handles using various formats, and an attempt to get the data is made so:

while (my $line = <MESSAGE>) { print $line; $text .= $line; } print $text;

The result is:

Use of uninitialized value in print at check_remove.pl line 85.

where line 85 is the print $text line. Opening MESSAGE in different modes does not yield better results. For instance, using the syntax in the open manpage results in a Filehandle MESSAGE opened only for output error. It works OK if I omit the handles and point the formats at STDOUT, but I am on Win32 and want to mail the output, so piping the output to SENDMAIL won't help. I was going to use Mail::Sendmail, which is why I want the output in a scalar. What am I missing?


In reply to open to a scalar variable by girarde

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.