***** infoCopter.com/perl *****

Monitored Variables

tie makes it really convenient to monitor a variable

Examples:

Monitoring change events of variables

#!/usr/bin/perl -w
use strict;

use Monitor;

my ($x, %y);

monitor(\$x, 'x');
monitor(\%y, 'y');

$x = 9;

$y{'foo'} = 'bar';

Output

$ ./monitor_var.pl
Wrote   $x ... 9
Wrote   $y{foo} ... bar
Died    $x
Died    %y

Check if any of a focussed hash key is set with one TRUE condition

use MonitorHash;

my %myhash = ();

my @keys = qw( fookey barkey );
pushElems(\@keys);
monitor_elems(\%myhash, 'myhash');

$myhash{'fookey'} = 'anything';

if (monitored_key_is_set('myhash')) {
        print "One of the specific keys is set in the monitored hash.\n";
}

[ Download: MonitorHash.pm ] - [ Download: Monitor.pm ]


Links

© reto :)