There are several dump trucks that can display variable names without requiring the programmer to explicitly repeat the name.
› perl -MData::Dumper::Simple -e'my $foo = 42; print Dumper($foo)'
$foo = 42;
Cheating is a source filter (often interrupted).
› perl -MDDS -e'my $foo = 42; DumpLex $foo'
$foo = 42;
The deception is PadWalker.
They also work with other types of variables to some extent, but fragments or other complex expressions are problematic.
What modern (after 5.10) trickery can be used to make the next sample dump truck (as in: a data structure viewer, not a eval
code producer)? The main focus is always on typing beautiful names, accepting multiple expressions and there is no need to change expressions with an additional reference level.
use 5.020; use Syntax::Construct qw(%slice);
use strictures;
use Acme::Hypothetical::Dumper 'd';
my %foo = (
Me => 'person',
You => 'beloved one',
Them => 'space aliens',
);
d %foo, $foo{'Me'}, @foo{qw(You Me)}, %foo{qw(You Me)};
my @bar = qw(Me You Them);
d @bar, $bar[0], @bar[2, 1], %bar[2, 1];
use LWP::UserAgent qw();
my $ua = LWP::UserAgent->new;
d $ua->{ssl_opts}{verify_hostname};