#!/usr/bin/perl
use warnings qw(all);
use strict;
use File::Copy qw(copy);
use File::Spec;
my $host = shift;
my $host_re = qr/$host/i;
my %files;
foreach my $path (@ARGV) {
my (undef, undef, $name) = File::Spec->splitpath($path);
$name =~ /^(.+)\.([^.]+)$/ or die "Bad file name: $name";
my ($group, $host) = ($1, $2);
if ($host =~ /^default$/i) {
$files{$group}{default} = $path;
} elsif ($host =~ $host_re) {
$files{$group}{host} = $path;
}
}
foreach my $group (sort keys %files) {
# must run with 5.8, no // operator...
my $path = defined $files{$group}{host}
? $files{$group}{host}
: $files{$group}{default};
defined $path or die "BUG: $group applies to us, but doesn't";
copy($path, *STDOUT);
}
Comments