Thanks for the help, Im slowly revising the code - I want to understand the code Im replacing before I replace it, so - so far this is where im at with the code.
Ok, Please note that to distinguish my code from yours, mine will be commented out (when in a paragraph by itself).

Note: the code I proposed the last time was rewritten from yours according to my own personal preferences. I tried to keep its general structure as close as possible to yours, though.

my (@hosts, @uphosts, @downhosts); if ( -e "ship.cfg" ) { open (CFGFILE, "ship.cfg") || die $!;
If you use a lexical filehandle then you do not need to close() it (when going out of scope (and if there are no more references to it)).

Personally I like to avoid all parentheses altogether and use the low priority C<and> for flow control. I like to use the three-args from of open() even if it is not strictly necessary for I think it's a good habit.

while (my @TMP=<CFGFILE>) {
Perl's idiom for reading "lines" (whatever these can be according to $/) is
# while (<CFGFILE>) {
If you want to do *exactly* the same with an explicit variable rather than $_, then you have to do
# while (defined(my $line = <ARGV>)) { # ... # }
What you wrote won't do what you think, since notwithstanding the C<while>, all of the file's content will be read into @TMP at a time.
#if ( $_ =~ /^#/ ) { next } # commented out in the OP
And $_ is?

Also, while legal, you're missing the whole point about $_: it's the implicit variable on which so many operators and functions act. So you either want to $variable =~ /something/ or /something/ (if your variable is $_).

Also, you may not like statement modifiers, but if there's a case in which one would come really handy is exactly this one: next if /^#/; (IMHO much more readable/immediate).

foreach $_(@TMP) {
Don't! Quite similarly you either do something for my $var (@list) { ... or for (@list) { ... (if you want to use $_).
if ($_ =~ /^([\w.]+)$/) {
Don't!
$_ = $1;
Why?!?
push (@hosts, $1); } else { next; }
No need for the C<next> block, as if the condition is not fulfilled it will pass to the next iteration anyway.
close (CFGFILE);
If you use a lexical filehandles then you do not need to close() them.
# Just cleaning up the verbage is are host hosts etc... if (scalar(@downhosts) == 1 ) { $verbage[2]="is"; $verbage[3]="host" if (scalar(@uphosts) == 1 ) { $verbage[0]="is"; $verbage[1]="host"; }
As I wrote the other time, no need for scalar() there, and you can use an array slice. Not to say that this is not correct, strictly speaking, only IMHO it is much cleaner the other way round. For an actual example see the sample code I posted in the other node.
# We don't care about things that don't exist... unless (scalar(@downhosts) == 0) { print p,"There $verbage[2] ",scalar
No need for the first scalar() as well as no need for the C<==0>. (No: this is not a mouse!! ;-)

The same cmts apply to much of the following code, I'm not repeating them.

Also, this is yet another one of those things that depend largely on personal preferences, but well written code should be self explanatory and only really relevant comments should be there. Commenting the obvious doesn't add to readability, IMHO: it has just the opposite effect instead!

Where Im at now is on this piece of code: # Iterate through my hosts and get their status push @{ $p->ping($_) ? \@uphosts : \@downhosts }, $_ for @hosts; $p->close();

what I get from this is if ping then either @uphosts (if successful) or @downhosts gets $_ from @host. Im just not getting why is it in the form of @{ $p->ping($_) ? \@uphosts : \@downhosts }

Well, it's just a way to do it that I find to be convenient. Of course it's up to your personal preferences. You may consider it to be slightly ineffcient, but we're dealing with only a bunch of them anyway and $p->ping($_) takes most of the time here.
and what does referencing @downhosts and @uphosts do that just calling them won't do? Or where can I read more on this other than perldata, perlref, etc...
Hint: push() wants an array as its first argument, I'm giving it one. I think perlref has all that is needed to be known. Check perlreftut, as well.

In reply to Re^3: using -T doesn't work by blazar
in thread using -T doesn't work by tcf03

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.