Awesome, an expert! =)
So, is it feasible?
update
Looks good to me, even with core modules. =)
use v5.12; # enable say & strict
use warnings;
{
package MySay;
use Data::Dump qw/pp dd/;
use Carp;
require Tie::Handle;
our @ISA = qw(Tie::Handle);
sub TIEHANDLE {
#carp pp '\@_: ', \@_;
bless \ my $i, shift
}
sub PRINT {
my $self = shift;
print STDOUT "$_" for @_
}
sub new {
my $self = shift;
open my $fh, ">&STDOUT";
tie *$fh, 'MySay';
return($fh);
}
# sub DESTROY {
# print STDOUT "DESTROY";
# # my $self = shift;
# select(STDOUT);
# }
}
{
package main;
# ---- test vars
$_='$_';
my @a = map { "\$a[$_]" } 0..2;
my @b;
{
select MySay->new();
say;
say @b;
say @a;
select(STDOUT)
}
say "AF","TER"
}
C:/Strawberry/perl/bin\perl.exe -w d:/tmp/pm/tie_handle.pl
$_
$a[0]
$a[1]
$a[2]
AFTER
with some effort it might even be possible to automatically destroy the selection at end of scope, such that one only needs to write MySay->select() once without any further need for visible select
But I got tired and wanted to get it done. :)
|