The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/local/bin/perl

use blib;
use strict;
use warnings;

use AFS::VLDB;

my ($vldb, $serv, $part, $lock, $Debugging);

$Debugging = 0;
if (defined @ARGV and $ARGV[0] eq '-d') { $Debugging = 1; shift; }
die "Usage: $0 [server [partition [lock]]]]\n" if $#ARGV > 2;

$serv = shift;
$part = shift;
$lock = shift;

$serv = '' unless $serv;
$part = '' unless $part;
$lock = 0  unless $lock;

$vldb = AFS::VLDB->new;
$AFS::CODE and print "AFS::CODE = $AFS::CODE\n";

my $vldblist = $vldb->listvldb($serv, $part, $lock);
$AFS::CODE and print "AFS::CODE = $AFS::CODE\n";

$Debugging && print_debug($vldblist);
print_vldblist($vldblist);

sub print_vldblist {
    my ($vldblist) = @_;

    foreach my $val (keys %$vldblist) {
        print "Key: $val\n";
        foreach my $ent (keys %{$vldblist->{$val}}) {
            if ($ent eq 'server') {
                my $i = 1;
                foreach my $srv (@{$vldblist->{$val}->{$ent}}) {
                    print "\tServer number $i:\n";
                    $i++;
                    foreach my $s (keys %{$srv}) {
                        print "\t\tKey: $s, Value: $srv->{$s}\n";
                    }
                }
            }
            else {
                print "\tKey: $ent, Value: $vldblist->{$val}->{$ent}\n";
            }
        }
    }
}

sub print_debug {
    my ($vldblist) = @_;

    foreach my $val (keys %$vldblist) {
        print "$val:\n";
        foreach my $ent (keys %{$vldblist->{$val}}) {
            if ($ent eq 'server') {
                printf "\t%10s \n", $ent;
                foreach my $srv (@{$vldblist->{$val}->{$ent}}) {
                    foreach my $s (keys %{$srv}) {
                        printf "\t\t%12s: %s\n", $s, $srv->{$s};
                    }
                }
            }
            else {
                printf "\t%10s: %s \n", $ent, $vldblist->{$val}->{$ent};
            }
        }
    }
    print "\n\n";
}