Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
If you want to use a regex like Oct 10 05:5[0-2]:, then I'd say you don't need "start" and "end" values, because the desired range from start to end is fully expressed in that one regex.

If the intent of your example is to catch everything between "Oct 10 05:50:00" and "Oct 10 05:52:59" inclusive, then a logical two-arg, start/end spec would look like this (which would be pretty simple for any naive user to understand):

script.pl --start 'Oct 10 05:50 --end 'Oct 10 05:52'
(Including specific seconds values in the start and/or end options would also be simple.)

Depending on what kind of data the script is going to do its "binary search" over, it might be more sensible to use one of the Date:: modules, to interpret both the user's ARGV values and the date values in the data being searched - i.e. something like:

my $user_start_date = get_secs_from_opt( $opt{start} ); my $user_end_date = get_secs_from_opt( $opt{end} ); for my $record ( @data_records ) { my $rec_date = get_secs_from_data( $record ); if ( $rec_date >= $user_start_date and $rec_date <= $user_end_date + ) { # do something with a hit... } }
The "get_secs_from_*" functions would just invoke some suitable Date:: module to return "unix_time" (or whatever term is used for "seconds since the epoch" in the chosen module).

But then, I'm not sure what you mean by "binary search", so maybe this isn't helpful.


In reply to Re: dynamic regex by graff
in thread dynamic regex by mhearse

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (11)
    As of 2014-10-02 12:01 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      What is your favourite meta-syntactic variable name?














      Results (56 votes), past polls