I have 2 arrays; one contains a list of say light switches, the other contains lines of comma separated values. The lines of comma separated values have $unixtime,$switchname,$state. For our purposes here there are multiple possible states of off and one possible state of on. I want to do something like

foreach (@switches) { find total time switch was off }

I am thinking I want to pattern match down to only one switch (the array is in order based on the unixtime column) then go through one at a time and find a line that doesn't match the /on/ pattern, then continue till I find a line that matches the /on/ pattern. Then substract column one of the on entry from column one from the off entry and add it to a total off time variable. The only other thing is that a switch can be turned on and off multiple times in our window. I am kind of new to perl and it is my first language so any help you can provide with the { find total time switch was off } part would really be appreciated. I know this has to be out there somewhere but I couldn't figure out what to search for so I decided to ask for help instead.

In reply to performing operation on multiple items in an array by vatheck

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.