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


In reply to Re^3: If line matches, print column, else print file name by haukex
in thread If line matches, print column, else print file name by Yakup

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.