in reply to Re: Formats and Variables
in thread Formats and Variables

I am but an egg, so perhaps I am missing something very basic, but I tried to do this and it didn't want to cooperate with write (it worked just fine with print). Since the point of my exercise is to avoid having to convert a large and complicated format into, well, anything else, I really was hoping to be able to capture the output of write to a variable. (If I have to use print, I might as well convert the whole thing to lots of little $var .= "my strings go here" which would be sub-optimal for other reasons.) Here's what's been happening:
use IO::Scalar; my $bufferVar = ""; my $SH = new IO::Scalar \$bufferVar; print $SH "Hi there, 1."; ### This works just dandy. select ($SH); print "Hi there, 2."; ### This also works. $bufferVar now contains "H +i there, 1.Hi there, 2." $~ = "myFirstFormat"; ### Allegedly this is happy. I have tested thi +s format independently, and it works fine. write ; ### This barfs.
It says: write() on unopened filehandle IO::Scalar::FH at format_test.cgi line 29 (#1) (W unopened) An I/O operation was attempted on a filehandle that was never initialized. You need to do an open(), a sysopen(), or a socket() call, or call a constructor from the FileHandle package.

Help?

Replies are listed 'Best First'.
Re: Re: Formats and Variables
by runrig (Abbot) on Jan 25, 2002 at 08:59 UTC
    Sorry, I later figured out that tied handles and write don't get along (when I actually needed to write to a scalar myself and wrote this node), but I had long forgot about what I wrote above. It took this long for someone to figure out that it was wrong, so congratulations, you have graduated from egg :-)