Thanks to all who replied. jcleland (with a slight refinement from grep) suggested the typical way for redirecting a stream. However that won't really work in this case as my brainfck instructions are transformed into hardcoded perl statements. greenFox's suggestion has the same problem.

Joost and dog andPony suggested two other modules. Of those IO::Scalar does the reverse of what I want i.e. it treats a scalar as a filehandle. Tie::Handle::Scalar on the other hand was perfect. The only stumbling block was that it is not part of the Perl core modules and asking people to install it just to run tests seems a bit extreme. Luckily the code is short enough that I could just include it verbatim in my test script. Normally this would be a maintainence problem but i'm not even using all the features of the current module so it won't be a problem if my local copy goes out of sync with the upstream version.

Here is the actual code from my test script. See the Inline::brainfck thread to understand the interpolated Brainfck code.

$a = "\t"; tie *STDIN, 'Tie::Handle::Scalar', \$a; my $b = , ; ok ( $b == 9, ' Does , work?'); untie *STDIN; $a = ''; tie *STDOUT, 'Tie::Handle::Scalar', \$a; .. ok ( $a eq "\t\t", ' Does . work?'); untie *STDOUT; $a = ''; tie *STDERR, 'Tie::Handle::Scalar', \$a; # ok ( $a eq "\$p = 1 \$m[\$p]= 9\n", ' Does # work?'); untie *STDERR;

--
જલધર


In reply to Re: Testing Input and Output by jaldhar
in thread Testing Input and Output by jaldhar

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.