in reply to how watch a variable

Devel::Peek::Dump is dumb as it always prints but getting the returned string back is not that easy. It's possible, though - but I'm not sure it's always helpful:
#! /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.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: how watch a variable
by LanX (Saint) on Dec 10, 2023 at 21:15 UTC

    Yes it just occurred to me that overload could help watching the result of an operation without XS

    nomethod could be used to check them all.

    > haven't succeeded in hiding the call to Dump in a tied or overloaded object.

    One anomonk in this thread tried to use B::Flags instead of Devel::Peek for this

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery


    PS: sorry for the duplicates, it took about 5 minutes before the monastery confirmed my posting, all prior attempts showed as duplicates.