Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I'll try to explain my code:
The new method just creates an empty object. The object is then populated by the populate method: it just remembers all the start end end points of all the intervals in times subhash. At each interval, it also remembers what value begins to be valid (push) or ceases to (pop).

The most important method is combine. It sorts all the time points and then walks through them, keeping track of all "active" values for the given interval (the active values are stored in @stack). All the values whose intervals start at the given point are inserted into the stack, all values whose intervals end at the given point are popped. The grep { not defined $value or $_ != $value or undef $value }construct just makes sure repeated values are removed one by one from the stack. Then, if there is no value left, the current output interval is closed and stored in @result. If there was no value before, but now there is, a new interval is started. If the value has changed, the interval is closed and a new one is opened.

Finally, the _day_split function is called on the result. It just examines each interval, and if it spans over several days, it splits it into several intervals. The first and last days are special, because their starting, resp. ending times are derived from the interval.

The _dec and _inc are just helper functions to subtract or add 1 to a time stamp. They are needed to avoid "overlapping" of intervals, i.e. in

1 7 |-----| (4) |--------| (3) 4 12
the first interval will end at 3, which is _dec(4).

In reply to Re^5: Date Array Convolution by choroba
in thread Date Array Convolution by alanonymous

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (5)
    As of 2020-10-23 21:34 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (241 votes). Check out past polls.