Commit 5b81c6ca authored by Peter Pentchev's avatar Peter Pentchev

Wrap the main loop in a block.

parent ac449302
......@@ -162,65 +162,68 @@ sub convert()
return \%devs;
}
$| = 1;
MAIN:
{
$| = 1;
my %opts;
my %opts;
getopts 'Cc:hi:Mn:tV', \%opts or usage(1);
version if $opts{V};
usage 0 if $opts{h};
exit 0 if $opts{V} || $opts{h};
getopts 'Cc:hi:Mn:tV', \%opts or usage(1);
version if $opts{V};
usage 0 if $opts{h};
exit 0 if $opts{V} || $opts{h};
$addtime = $opts{t};
if (defined $opts{n}) {
if ($opts{n} !~ /^([1-9]\d*)$/) {
warn "The period must be a positive integer\n";
usage 1;
$addtime = $opts{t};
if (defined $opts{n}) {
if ($opts{n} !~ /^([1-9]\d*)$/) {
warn "The period must be a positive integer\n";
usage 1;
}
$period = $1;
}
$period = $1;
}
if (defined $opts{c}) {
if ($opts{c} !~ /^([1-9]\d*)$/) {
warn "The count must be a positive integer\n";
usage 1;
if (defined $opts{c}) {
if ($opts{c} !~ /^([1-9]\d*)$/) {
warn "The count must be a positive integer\n";
usage 1;
}
$count = $1;
}
$count = $1;
}
$iface = $opts{i}; # also works if it isn't defined
$iface = $opts{i}; # also works if it isn't defined
if ($opts{C}) {
if ($opts{M}) {
die "The -C and -M options are mutually exclusive\n";
} elsif (!$have_ansi_color) {
die "The Term::ANSIColor Perl module is not available\n";
}
$COLOR = 1;
} elsif ($opts{M}) {
$COLOR = 0;
} else {
$COLOR = $have_ansi_color && -t \*STDOUT;
}
if ($opts{C}) {
if ($opts{M}) {
die "The -C and -M options are mutually exclusive\n";
} elsif (!$have_ansi_color) {
die "The Term::ANSIColor Perl module is not available\n";
}
$COLOR = 1;
} elsif ($opts{M}) {
$COLOR = 0;
} else {
$COLOR = $have_ansi_color && -t \*STDOUT;
}
my $op = $period;
$period = 1;
convert;
sleep $period;
my $op = $period;
$period = 1;
convert;
sleep $period;
while(1) {
my $devs = convert;
print time.' ' if $addtime;
if (scalar keys %{$devs} > 1) {
say acolor('yellow').
format_line('total', \%total).
acolor('reset');
}
foreach my $dev (sort { $a->{name} cmp $b->{name} } values %{$devs}) {
say format_line($dev->{name}, $dev->{data});
}
if (defined $count) {
$count--;
exit 0 if $count < 1;
while(1) {
my $devs = convert;
print time.' ' if $addtime;
if (scalar keys %{$devs} > 1) {
say acolor('yellow').
format_line('total', \%total).
acolor('reset');
}
foreach my $dev (sort { $a->{name} cmp $b->{name} } values %{$devs}) {
say format_line($dev->{name}, $dev->{data});
}
if (defined $count) {
$count--;
exit 0 if $count < 1;
}
$period = $op;
sleep $period;
}
$period = $op;
sleep $period;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment