in reply to how watch a variable
#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; use experimental qw( signatures ); use Devel::Peek qw{ Dump }; sub _dump { my @failures; open my $olderr, '>&', \*STDERR or push @failures, $!; close *STDERR; open *STDERR, '>', \ my $err or push @failures, $!; eval { Dump($_[0]); 1 } or push @failures, $@; open *STDERR, '>&', $olderr or push @failures, $!; die @failures if @failures; my ($type) = $err =~ /FLAGS = \((.*)\)/; say $type; return $type } { my $c = 123; my $before = _dump($c); die unless $c < 130; say "II:", $before eq _dump($c) ? 'Same' : 'Changed'; } { my $c = 123; my $before = _dump($c); die unless $c lt 130; say "IP:", $before eq _dump($c) ? 'Same' : 'Changed'; } { my $c = 123; my $before = _dump($c); die unless $c < 130.01; say "IN:", $before eq _dump($c) ? 'Same' : 'Changed'; } { my $c = 123.01; my $before = _dump($c); die unless $c < 130; say "NI:", $before eq _dump($c) ? 'Same' : 'Changed'; } { my $c = 123.01; my $before = _dump($c); die unless $c lt '130'; say "NP:", $before eq _dump($c) ? 'Same' : 'Changed'; } { my $c = 123.01; my $before = _dump($c); die unless $c < 130.01; say "NN:", $before eq _dump($c) ? 'Same' : 'Changed'; } { my $c = '123'; my $before = _dump($c); die unless $c lt 130; say "PP:", $before eq _dump($c) ? 'Same' : 'Changed'; } { my $c = '123'; my $before = _dump($c); die unless $c < 130; say "PI:", $before eq _dump($c) ? 'Same' : 'Changed'; } { my $c = '123'; my $before = _dump($c); die unless $c < 130.01; say "PN:", $before eq _dump($c) ? 'Same' : 'Changed'; }
Output:
IOK,pIOK IOK,pIOK II:Same IOK,pIOK IOK,POK,pIOK,pPOK IP:Changed IOK,pIOK IOK,NOK,pIOK,pNOK IN:Changed NOK,pNOK NOK,pIOK,pNOK NI:Changed NOK,pNOK NOK,pNOK NP:Same NOK,pNOK NOK,pNOK NN:Same POK,IsCOW,pPOK POK,IsCOW,pPOK PP:Same POK,IsCOW,pPOK IOK,POK,IsCOW,pIOK,pPOK PI:Changed POK,IsCOW,pPOK NOK,POK,IsCOW,pNOK,pPOK PN:Changed
Note the "NP:Same" lines. Also, changing 130.01 to 130.0 makes a difference. What's even worse, changing the Perl version makes a difference. With 130.0, 5.26.1 gives "NN:Changed", but blead gives "NN:Same" (it doesn't add pIOK to NOK,pNOK).
I haven't succeeded in hiding the call to Dump in a tied or overloaded object.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how watch a variable
by LanX (Saint) on Dec 10, 2023 at 21:15 UTC |