Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
more useful options
 
PerlMonks  

Re^3: improving the aesthetics of perl code

by pingo (Hermit)
on Jan 21, 2005 at 11:23 UTC ( [id://424034]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 11: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 17: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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://424034]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.