Hi all,
I have been working on a problem and worked out a solution, but am
wondering if there is an easier(more elegant?) way of doing it. I am
automatically generating configuration files for a Quality Of Service(QOS)
device, and each pipe in the QOS has a policy number attached to it. The
policy numbers must be unique, so I have to find an unused number. The
system never has more than 200 or so policies. I am pulling the preexisting
policy numbers out of a database and placing them into an array(@addarr)
Here is my code:
#!/usr/bin/perl
use Mysql;
$db = Mysql->connect('localhost', 'dbase', 'user', 'password');
$query = $db->query("SELECT policy FROM Table");
while ( $policy = $query->fetchrow_array()) {
$addarr[$policy] = $policy;
}
for ($i = 1; $i < 1001; $i++) {
if (defined($addarr[$i])) {
next;
} else {
$newaddr = $i;
last;
}
}
where $newaddr would be the new, as yet unused, number
Thanks
Wes Phillips