Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How to calculate values based on date / time stamp?

by InfiniteSilence (Curate)
on Jan 30, 2012 at 01:47 UTC ( #950683=note: print w/ replies, xml ) Need Help??


in reply to How to calculate values based on date / time stamp?

Couple of pieces of advice:

  • Stop parsing delimited strings by hand. You can use Text::CSV
  • even for something with a different separator as the perldoc says, "The module accepts either strings or files as input and can utilize any user-specified characters as delimiters, separators, and escapes so it is perhaps better called ASV (anything separated values) rather than just CSV.'
  • Try perldoc -q switch instead of those if statements.
  • For your question, provided you have an ordered set of times, I would quantize them to multiples of five and then aggregate them in a hash. For instance:
    linux~> perl -e 'my @quant = (); my @times = qw|12 14 21 27 30|; sub r +ound{while (@_[0]%5 != 0){@_[0]++}; return @_[0]}; for(@times){print +round($_), qq|\n|};'

Celebrate Intellectual Diversity


Comment on Re: How to calculate values based on date / time stamp?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://950683]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2015-07-07 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls