in reply to Re^3: Array Problem
in thread Array Problem

Here is the changed section of the code:

open(RESULTS2, "ping.txt") || die; @results = <RESULTS2>; open(RESULTS, ">ping.txt") || die; $j = 1; $a = 0; $f = 0; while (@results) { print $_; if (m/Reply/) { $output[$j] = $baseIP.$j.": Alive\n"; $j++; $a++; } elsif (m/Request/) { $output[$j] = $baseIP.$j.": Dead\n"; $j++; $f++; } else { #@output[$j] = $baseIP.$j.": Unusual Results, requires Manual Ping +\n"; } } print RESULTS "Pinger Results:\n\n"; print RESULTS "Alive Nodes: $a\n"; print RESULTS "Dead Nodes: $f\n"; print RESULTS "\n\nDetailed Results:\n"; print RESULTS @output; close(RESULTS); close(RESULTS2);

Replies are listed 'Best First'.
Re^5: Array Problem
by Transient (Hermit) on Jul 08, 2005 at 15:46 UTC
    you're getting that warning (and an infinite loop also) because you're using "while" instead of "foreach".

    while only automatically sets $_ in the following case:
    while (<FILE>)
    otherwise, it does not.