in reply to Re^2: Spotting an empty array as argument
in thread Spotting an empty array as argument
So, is it feasible?
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. :)
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Spotting an empty array as argument (updated: select tied handle)
by haukex (Archbishop) on Mar 27, 2021 at 08:55 UTC |