in reply to Array Problem

open(RESULTS2, "ping.txt") || die; open(RESULTS, ">ping.txt") || die;
You open a file for reading and then you truncate that file before reading from it. Try moving the write after reading (and closing) the first filehandle - or try writing to a different file.

Replies are listed 'Best First'.
Re^2: Array Problem
by wanderinweezard (Initiate) on Jul 08, 2005 at 14:37 UTC
    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?
      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);