in reply to open to a scalar variable

Don't put quotes around the variable (see open).

open(MESSAGE, '+>>', \$message) or die "no message $!";

(What you're doing is opening a file literally named "$message".)

Replies are listed 'Best First'.
Re^2: open to a scalar variable
by girarde (Hermit) on Jun 05, 2007 at 13:56 UTC
    Unquoting \$message yielded an "uninitialized value" error at the print statement.

      Putting together some of the other suggestions in this thread, I come up with this:

      my $message = ''; open(MESSAGE, '+>>', \$message) or die "no message $!"; open(WHOM, '>>&=MESSAGE') or die "no whom $!"; open(WHAT, '>>&=MESSAGE') or die "no what $!"; print WHOM "I say 'whom'\n"; print WHAT "I say 'what'\n"; my $text; while (my $line = <MESSAGE>) { print $line; $text .= $line; } print $text; __END__ I say 'whom' I say 'what' I say 'whom' I say 'what'