in reply to Re^2: improving the aesthetics of perl code
in thread improving the aesthetics of perl code

Looks fine to me, but I am not exactly an expert myself. :-) One thing that I guess could be written differently is this:
foreach $_(@TMP) { if ($_ =~ /^([\w.]+)$/) { $_ = $1; push (@hosts, $1); } else { next; } }

Something like this, perhaps:

foreach (@tmp) { push @hosts, $1 if /^([\w.]+)$/; }
I may be missing something blindingly obvious, though. :-)

Replies are listed 'Best First'.
Re^4: improving the aesthetics of perl code
by Tanktalus (Canon) on Jan 21, 2005 at 16:29 UTC

    Not blindingly obvious, no. What you probably missed is the -T at the top of the code. This means that the original code will untaint parts of @TMP (assigning to $_ should affect the original array entry) at the same time as making a wholly untainted @hosts. Since @TMP doesn't seem to be used again, the $_=$1 part seems somewhat useless ;-)

Re^4: improving the aesthetics of perl code
by jdporter (Paladin) on Jan 21, 2005 at 22:25 UTC
    I'd write that as
    push @hosts, map { /^([\w.]+)$/ ? $1 : () } @tmp;
    Not that I make any claims for its aesthetics. :-)
      Why not...
      @hosts = map { /^([\w.]+)$/ ? $1 : () } @tmp;
      update: might as well get rid of the @tmp while we're at it...
      @hosts = map { /^([\w.]+)$/ ? $1 : () } <CFGFILE>;


      -- All code is 100% tested and functional unless otherwise noted.