# * "Save as" the file "COLO Cabinet Layout.*" as .csv with the default
# settings from LibreOffice Calc, generating "COLO Cabinet Layout.csv"
#
+# * Likewise for "selections.ods"
+#
# * Run
-# ./convert-cabinet-layout "COLO Cabinet Layout.csv";
+# ./convert-cabinet-layout "COLO Cabinet Layout.csv" "selections.csv";
#
# * Paste the output in appropriate places
#
die unless @ARGV==1;
-our $inputfile = shift @ARGV;
+our ($csv,$csv_fh);
-my $csv = Text::CSV->new or die $!;
+sub csv_start ($) {
+ my ($inputfile) = @_;
+ $csv = Text::CSV->new or die $!;
+ $csv_fh = new IO::File $inputfile, "<:encoding(utf8)"
+ or die "$inputfile $!";
+ my $headings = $csv->getline($csv_fh);
+ die $! unless $headings;
+ $csv->column_names($headings);
+}
-my $fh = new IO::File $inputfile, "<:encoding(utf8)" or die "$inputfile $!";
+sub csv_row () {
+ $csv->getline_hr($csv_fh)
+}
-my $headings = $csv->getline($fh);
-die $! unless $headings;
-$csv->column_names($headings);
+sub csv_end () {
+ close $csv_fh or die $!;
+}
our $machine;
our @machines;
-while (my $row = $csv->getline_hr($fh)) {
+csv_start($ARGV[0]);
+
+while (my $row = csv_row()) {
print DEBUG Dumper($row);
$machine = $row->{'Server / Appliance'};
"./mg-hosts setflags @machines -- @flags\n";
}
-close $fh or die $!;
+csv_end();
foreach my $dest (sort { $dests{$a} <=> $dests{$b} } keys %dests) {
print "\n#-------------------- $dest --------------------\n" or die $!;