in reply to Re: a use for hashes?
in thread a use for hashes?

Thanks - that worked great! ..but it got me thinking. How could I do the same thing only instead of processing your code on a finished file if I could do the same thing as the file is being built? In other words, when code hits a relay that has already appeared with a state, the newly read state would be "pushed" along side of the previous one.

Replies are listed 'Best First'.
Re^3: a use for hashes?
by ikegami (Patriarch) on Feb 02, 2010 at 17:40 UTC
    Just replace the line that writes to the file with push @{ $relays{$id} }, $state;
      Thanks ikegami! ..one last ?: if I have a relay followed by a number of states, e.g., relay1 on off set reset, how would I create an array or hash where the first element would contain the relay and the second would contain all of the various states - i.e., $ele[0] = relay1 $ele1 = on off set reset?
        Well, which one? Hash:
        my %relays; while (<>) { chomp; my ($id, $states) = split(' ', $_, 2); $relays{$id} = $states; }

        Array:

        my @relays; while (<>) { chomp; my ($id, $states) = split(' ', $_, 2); push @relays, [ $id, $states ]; }