in reply to Re^2: If line matches, print column, else print file name
in thread If line matches, print column, else print file name
Hi Yakup,
Glad to hear your code is doing what you want. I do have to admit I found the logic a bit hard to follow, but that isn't necessarily a problem. I would however recommend you run the code through enough test cases, just to make sure.
I just wanted to point out a few potential improvements:
If I implement those suggestions, I get:
#!/usr/bin/env perl use strict; use warnings; use FindBin; use File::Basename qw/fileparse/; use List::Util qw/any/; my $lab_root = $FindBin::Bin; my @kickstarts = glob "$lab_root/*.ks"; my @bsname; my @predefined; for my $kickstart (@kickstarts) { open my $fh, '<', $kickstart or die "Cannot open $kickstart: $!"; while (<$fh>) { chomp; next if /^\s*#/; if (/--hostname=/) { my @fields = split /[=\s]/; push @bsname, $fields[1]; push @predefined, $kickstart; } } close $fh; next if any {$kickstart eq $_} @predefined; my $hostname = fileparse($kickstart, qr/\.ks$/i); push @bsname, $hostname; }
Note that in this code compared to yours, the filenames now all have their pathnames prefixed. Since I don't know what the rest of your code does, this may or may not be a problem for you. If it is, you could for example use the same fileparse function to get only the filename.
Hope this helps,
-- Hauke D
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: If line matches, print column, else print file name
by Yakup (Novice) on Oct 26, 2016 at 15:00 UTC |