http://qs321.pair.com?node_id=455705

hok_si_la has asked for the wisdom of the Perl Monks concerning the following question:

Greetings monks

I need to come up with an algorithm to find $j sequential IP addresses within a single $vlan if. It is possible that there is not $j sequential address within the table. In that case $j addresses will be selected by the lowest value of difference between the highest octet4 and lowest octet4.

The code below selects $j IPs from $vlan according to their location within the table. I should also add that although there are many things that may need be changed regarding syntax, I really only have 30 mins to get this cranking.
Any ideas? Is there a quick way to do this?

Each $vlan contains about 250 or so address & $j <= 5

############################################################ sub getips ############################################################ { my $j = shift; my $vlan= shift; my $name = "ips" . $j; my ($sth, $dbh, %ips, $i, @iparray); $dbh=DBI->connect('DBI:ODBC:Servers', { RaiseError => 1, AutoCommit => + 0 }); $sth = $dbh->prepare( "SELECT IPs.* FROM IPs LEFT OUTER JOIN StaticIP +s ON IPs.Octet1 = StaticIPs.octet1 AND IPs.Octet2 = StaticIPs.octet2 +AND IPs.Octet3 = StaticIPs.octet3 AND IPs.Octet4 = StaticIPs.octet4 W +HERE (StaticIPs.octet1 IS NULL) AND (IPs.VLAN = '$vlan')" ); $sth->execute; $sth->bind_columns( \( @ips{ @{$sth->{NAME_lc} } } )); #----Saves spe +ed by binding columns to their values. See netTools_help.doc. $sth->{'ChopBlanks'} =1; #----Removes extra spaces from fixed char +fields. See netTools_help.doc. $i=0; while ($sth->fetch) { if ($ips{'octet1'}) { $iparray[$i]=join(".", "$ips{'octet1'}", "$ips{'octet2'}", "$ips{' +octet3'}", "$ips{'octet4'}"); } ++$i; } $j--; print scrolling_list(-class=>'df', -name=>'$name', -values=>[@iparray] +, -size=>'1', -default=>$iparray[$j]); $sth->finish(); $dbh->disconnect(); #----Needed to free up system resources. }

Thanks in advance,
hok_si_la