Laurent_R, GotToBTru thanks a lot to both of you for pointing out mistakes in my code. I don't know how could I not notice them before. I have followed your advices to edit the code and also edited few other things and now it works as expected.
#!/usr/bin/env perl use strict; use warnings; use File::Basename; my $lab_root = dirname $0; opendir( DH, $lab_root) or die "Cannot open $lab_root: $!\n"; my @kickstarts = grep ( /\.ks$/, readdir(DH)); my @bsname ; my @predefined; my $hostname; for my $kickstart (@kickstarts) { open my $fh, $kickstart or die "Cannot open $kickstart: $!"; while (<$fh>) { chomp; if ( /(?s)^((?!#).)*--hostname=/ ) { my @fields = split /[=\s]/; $hostname = $fields[1]; push @bsname , $hostname; push @predefined , $kickstart; } } close $fh; next if $kickstart ~~ @predefined; $hostname = (split /\./, $kickstart )[0]; push @bsname, $hostname; }
In reply to Re^2: If line matches, print column, else print file name
by Yakup
in thread If line matches, print column, else print file name
by Yakup
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |