Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi monks,

I have subroutine which gets two params
PARAM1 -> <time_stamp> Ex:200504250946
PARAM2 -> <interval> Ex:15 || 30 only

%normalise_with_this = ( 15 => { 00 => [ 0 .. 14 ], 15 => [ 15 .. 29 ], 30 => [ 30 .. 44 ], 45 => [ 45 .. 59 ] }; 30 => { 00 => [ 0 .. 29 ], 30 => [ 30 .. 59 ] }; );
The function has to extract the minutes from time_stamp (i,e) substr("200504250946",10,2) which results '46' from the example.
Interval is passed as 15.
from the hash "%normalise_with_this" using interval value I have to acess the first level of hash that is 15 or 30,
in our case I have to access 15.
From this I am able to access the second level of hash with the keys '00','15','30','45'.
In any of the values '46' will be there. In our case key '45' contains, 46 in it. (i,e) "45 .. 59 ".
How to point this efficiently using the above inputs which comes as a param to a function.
So function has to return the key 45.
If minute is 34, then function has to retun 30. because 34 lies in 30 => " 30 .. 44 ".

"Keep pouring your ideas"

2006-04-25 Retitled by holli, as per Monastery guidelines
Original title: 'Ideas requested from all monks members'


In reply to Round time to nearest 15 or 30 minutes by jesuashok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found