Comments for Perl Advent Calendar Entry 7th Dec 2003. Comments posted below may be displayed on perladvent.org.
I would find monitoring multiple variables all called $VAR1
frustrating. So I would want to extend the example to use the 2-arg version of Data::Dumper::Dump
. Finger-painting, we can replace the Report loop with
print Data::Dumper::Dump([@monitoring{sort keys %monitoring}],[sort keys %monitoring]);
To do that, we need to capture the name of the monitored variable, so we replace
push @monitoring, $referent;
with
except that doesn't work for the lexicals illustrated, so would have to detect $symbol eq 'LEXICAL' and look for an attribute argument in $data, such as 'Monitor(name=>Fred)'.$monitoring{*{$symbol}{NAME}}=$referent;
Which makes it so messy I understand why you kept the example simple!
Cheers,
Bill