Michael Gale wrote:
> ...
> m|output:DISK (\w+) \[(\d+) kB \((\d+)%\) free on (\S+)\]| and do {
> my $status = $1;
> my $kb_free = $2;
> my $pct_free = $3;
> my $mount = $4;
> push @s, [ $mount, [ blockpct, GAUGE, $pct_free ] ];
> };
>
> I do not understand the "and do" option.
"do" here turns a block into an expression. The "and" causes the RHS to be
evaluated if the LHS is true. In otherwords, if the m|| match succeeds,
evaluate the stuff in the do {} block. This notation is legal, but a bit
unusual. The equivalent, and more common construct would be:
if (m|output:DISK (\w+) \[(\d+) kB \((\d+)%\) free on (\S+)\]|) {
my $status = $1;
my $kb_free = $2;
my $pct_free = $3;
my $mount = $4;
push @s, [ $mount, [ blockpct, GAUGE, $pct_free ] ];
};
The important thing for both formats is to always test whether the pattern
match succeeds before attempting to use $1, $2, etc.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>