in reply to Divert STDOUT temporarily

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11116125 use warnings; print "one\n"; do { local *STDOUT; open STDOUT, '>', '/dev/null' or die; print "two\n +"; }; print "three\n";

Replies are listed 'Best First'.
Re^2: Divert STDOUT temporarily
by jwkrahn (Abbot) on Apr 27, 2020 at 19:05 UTC
    do { local *STDOUT; open STDOUT, '>', '/dev/null' or die; print "two\n +"; };

    You don't need a do{} block when just a bare block will do:

    { local *STDOUT; open STDOUT, '>', '/dev/null' or die; print "two\n"; +}
Re^2: Divert STDOUT temporarily
by Xilman (Hermit) on Apr 27, 2020 at 19:02 UTC

    Many thanks.

    Initial response is "Doh!"

    Second response: I knew I was becoming senile.