in reply to Re: Array Problem
in thread Array Problem

I did tr that, now I get an error of:

Use of uninitialized value in pattern match (m//) at pinger.pl line 22, <RESULTS2> line 1016.

Any idea what could cause that?

Replies are listed 'Best First'.
Re^3: Array Problem
by Transient (Hermit) on Jul 08, 2005 at 14:41 UTC
    I'd have to see your updated code.
      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);
        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.