Hi there fellow PERL coders.
I am trying to match lines between a template file and a configuration
file. If the configuration is missing a particular line that is found
in the template file then it is printed. If the configuration file has
an extra line then it to gets printed.
Something isnt working here. I am not getting the lines to match an I
cant seem to figure out why. I am hoping somebody can shed some light here.
Cheers,
Noah
#!/sw/bin/perl -w
#
#
my $version_directory = "VERSION";
my $config_directory = "CONFIGS";
my $log_directory = "LOGS";
my $nologin_directory = "NOLOGIN";
my $template_directory = "Configuration_Templates";
my @config_template_filenames =
("$template_directory/blah1.sample.configuration.txt","$template_directory/blah2.sample.configuration.txt");
my $filename_match = ".set.config.txt";
open (blah1, $config_template_filenames[0]) || die "Cannot open
'$config_template_filenames[0]' $!";
@blah1_file_lines=<blah1>;
close (blah1);
open (blah2, $config_template_filenames[1]) || die "Cannot open
'$config_template_filenames[1]' $!";
@blah2_file_lines=<blah2>;
close (blah2);
for (@blah2_file_lines) {
print $_;
}
# verify the directories are there
if (!(-d $version_directory)) {
mkdir $version_directory;
}
if (!(-d $log_directory)) {
mkdir $log_directory;
}
if (!(-d $config_directory)) {
mkdir $config_directory;
}
if (!(-d $nologin_directory)) {
mkdir $nologin_directory;
}
foreach $file (<$config_directory/*.set.config.txt>) {
open (INPUT,$file) || die "Cannot open '$file' $!";
@config_file_lines = <INPUT>;
close (INPUT);
undef (@template_file_lines);
for $line (@config_file_lines) {
if ($line =~ /LSQ_blah1_OPTIONS/) {
@template_file_lines = @blah1_file_lines;
$template_type = "blah1";
} elsif ($line =~ /blah2-T1-OPTIONS/) {
@template_file_lines = @blah2_file_lines;
$template_type = "blah2";
}
}
die "Cant figure out where to use blah1 or blah2 template
configuration file.\n\n\n" if (!(@template_file_lines));
$hash1{$_} = 1 foreach (@config_file_lines);
$hash2{$_} = 1 foreach (@template_file_lines);
%hash1temp = %hash1;
%hash2temp = %hash2;
foreach (keys %hash1) {
delete $hash2temp{$_};
}
foreach (keys %hash2) {
delete $hash1temp{$_};
}
print "Extra items in list1:\n";
print "$_" foreach (sort (keys %hash1temp));
exit;
print "Extra items in list2:\n";
print "$_\n" foreach (keys %hash2temp);
exit;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/