January 2002
Beginner
480 pages
13h 15m
English
The set_status() function receives the
latest light value as polled from the sensor
and compares it with the pivot value. If the status defined in $new_status is different from the
current status (in $current_status),
then the current status is updated and returned; otherwise, undef
is returned:
sub set_status {
my $val = shift;
my $new_status = $val < $opts{'l'} ? COFFEE : NOCOFFEE;
if ($new_status != $current_status) {
$current_status = $new_status;
return $current_status;
}
else {
return undef;
}
}
If this function returns a status value, a new
<presence/> element is generated and
emitted by the script. Otherwise, there’s no change (“the coffee’s still
there,” or “there’s still no coffee!”) and nothing happens.
Read now
Unlock full access