7th Dec 2003

advent on 2003-12-07T23:45:45

Comments for Perl Advent Calendar Entry 7th Dec 2003. Comments posted below may be displayed on perladvent.org.


Also of interest

drhyde on 2003-12-08T09:09:27

is Scalar::Properties, which also allows for attaching out-of-band information to scalars. While it can have some odd side-effects, it's easier to use.

Monitoring with Names

n1vux on 2003-12-11T22:06:11

I am really glad you included this example, since I was thinking on the previous Tied example that an Attribute autotie would be a useful helper for that one.

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

$monitoring{*{$symbol}{NAME}}=$referent;
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)'.

Which makes it so messy I understand why you kept the example simple!

Cheers,
Bill