Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
You need the format_write and format_top_name methods (and maybe others, depending on how sophisticated your form handling needs to be). IO::Tee inherits some format-handling code from IO::Handle. The docs for IO::Tee really only mention it in passing, but it becomes clearer in the docs for IO::Handle, and you need to be sure to tell IO::Tee specifically about things like which format to use for top-of-form (which is "automatic" for STDOUT and the like).

The following code snippet should get you started. Notice that since the name of the format is passed down to IO::Tee, you need to specify the full package name of the format (o/wise you get complaints about undefined formats from IO::Tee).

use strict; use warnings; use IO::Tee; my( $abc, $xyz ) = ( q/hello/, 12345 ); format TEE_TOP = ==== Top of Output ==== . format TEE = @<<<<< @##### $abc, $xyz . # with lexical file handle; can also use bareword handle open my $outfile, '>', 'junk.out' or die "error opening junk.out: ($! +)"; my $tee = IO::Tee->new( \*STDOUT, $outfile ); # see docs for IO::Tee and IO::Handle for explanation of these methods # and others available for proper format use/control $tee->format_top_name( q/main::TEE_TOP/ ); $tee->format_write( q/main::TEE/ );

From the shell:

-> ./tst-tee-write ==== Top of Output ==== hello 12345 -> cat junk.out ==== Top of Output ==== hello 12345

In reply to Re: IO::Tee and write / format by broomduster
in thread IO::Tee and write / format by beadon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-25 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found