![]() |
![]() |
9 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl
use Net::IP;
my $ip = new Net::IP('192.168.0/24') or die(Net::IP::Error());
#Usage() if (@ARGV != 0 and $ARGV[0] eq "-h");
sub get_hosts{
return new Net::IP($_[0]->last_ip())->intip() - $_[0]->intip();
}
print get_hosts($ip)."\n";
# Berechnung des ld()
print log(get_hosts($ip))/log(2);
# Lange schreibweise, vllt stimmt ja an der Funktion was nicht
print log((new Net::IP($ip->last_ip())->intip()) - ($ip->intip()));
Can't use an undefined value as an ARRAY reference at /usr/share/perl/5.8/Math/BigInt/Calc.pm line 1376.
(my $ip)=@_;
Quote
Quote2. wäre vielleicht gut zu wissen welche Zeile denn Zeile 1376 ist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1367 sub _log_int
1368 {
1369 # calculate integer log of $x to base $base
1370 # ref to array, ref to array - return ref to array
1371 my ($c,$x,$base) = @_;
1372
1373 # X == 0 => NaN
1374 return if (scalar @$x == 1 && $x->[0] == 0);
1375 # BASE 0 or 1 => NaN
1376 return if (scalar @$base == 1 && $base->[0] < 2);
1377 my $cmp = _acmp($c,$x,$base); # X == BASE => 1
1378 if ($cmp == 0)
1379 {
1380 splice (@$x,1); $x->[0] = 1;
1381 return ($x,1)
1382 }
1383 # X < BASE
1384 if ($cmp < 0)
1385 {
1386 splice (@$x,1); $x->[0] = 0;
1387 return ($x,undef);
1388 }
1389
Quote3. deine Programmierart find ich persöhnlich grausam, du lässt Berechnungen und Funktionsaufrufe im print-Befehl machen....
4. man arbeitet nie direkt mit @_ in Funktionen, könnte auch der Fehler sein,
Code: (dl )(my $ip)=@_;
Quotewobei ich zugeben muss, dass ich deine sub get_hosts net wirklich kapiere^^
Quote"Can't use an undefined value
as an ARRAY reference" heisst: "Kann keinen undefinierten Wert als Arrayreferenz benutzen".
Quote$base ist undef, das erklärt die fehlermeldung.
1
2
3
4
5
6
my $zahl;
chomp($zahl =<STDIN>);
my $ausgabe = log($zahl);
# Für bieber;)
print $ausgabe;
print $ip->intip;
1 2 3
sub get_hosts{ return (new Net::IP($_[0]->last_ip())->intip() - $_[0]->intip())->numify; }
QuoteDas ist aber alles Math::BigInt Objekte.
![]() |
![]() |
9 Einträge, 1 Seite |