Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: improving the aesthetics of perl code

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


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 (Canon) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://424034]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2020-11-28 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?