8 Einträge, 1 Seite |
1
2
3
4
5
6
7
use Net::Telnet ();
$t = new Net::Telnet;
$t->open("192.168.0.90");
$t->login("admin", "passwort");
@lines = $t->cmd("show dsl stat");
@maxrate = grep /Current Attainable Rate/, @lines;
my $value = (split(/\s/,$maxrate[0]))[-1];
$maxrate[0] =~ s/.*?(\d+)$/$1/;
@array =~ s/.*?(\d+)$/$1/;
1
2
3
4
5
6
sub first_match ($@) {
my ($regex, @data) = @_;
my $result;
for (@data) { $result = $1 and last if /$regex/ }
return $result;
}
my $max = first_match qr/Current Attainable Rate -\s*(\d+)/, @lines;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
The regular expression:
(?-imsx:.*?(\d+)$)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
$ before an optional \n, and the end of the
string
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
Applying substitution (s///) to @array will act on scalar(@array) at skript.pl line 9.
$maxrate[0] =~ s/.*?(\d+)$/$1/;
$maxrate[0] = (split(/\s/,$maxrate[0]))[-1];
8 Einträge, 1 Seite |