in reply to saving search results to file

I've been using the following, but it's obviously not as elegant as tee. I need to dig into tee's guts and find out how it does what it does.
topen('STDOUT','>file1.txt','>>file2.txt'); tprint("text\n"); tprint("text\n"); tclose(); BEGIN { my (@tp_h, $tp_s); sub topen { tclose(); for (@_) { if ($_ eq 'STDOUT') { $tp_s = 1; next; } open($_, $_) || die $!; push @tp_h, $_; } } sub tclose { close $_ for @tp_h; @tp_h = (); $tp_s = 0; } sub tprint { print @_ if $tp_s; print $_ @_ for @tp_h; } }

Replies are listed 'Best First'.
Re^2: saving search results to file
by Animator (Hermit) on May 03, 2005 at 16:58 UTC

    IO::Tee does the same thing as what I would do:

    Tieing itself to a filehandle, and printing to all filehandles when you print to it...