This script runs twice every hour at both 00mins15secs and 30mins15secs. I am trying to select the nearest time before the 30min or 00min but NOT AFTER from an input file that can look like this.
//SNAGIT.TXT eg top of the hour 1.29133 ,01:59:34 1.29132 ,01:59:59 1.29132 ,01:59:59 .....
desired pair - 1.29132 ,01:59:59
//SNAGIT.TXT e.g bottom of the hour 1.29020 ,01:29:52 1.29036 ,01:30:02 1.29035 ,01:30:12 ....
desired pair - 1.29020 ,01:29:52

the code i have come up to achieve this is below, (i need the pattern matching regex to filter out dirty data.)
use Time::ParseDate; use Time::Local; ... my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdist) = localtime +time; my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)) [(lo +caltime)[4]]; my $day = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]]; $year = $year+1900; my $input = "SNAGIT.txt"; my $actualquote1=0; ## Open the SNAGIT.TXT, plus some sensible error checking open(DATAFILE, "$input") || die("Can't open $input:!\n"); ## Loop through the file one line at a time while (<DATAFILE>) { chomp; if ( m{^ (\d\.\d{5}) \s*,\s* (\d\d:\d\d:\d\d) \s* (.*) $ }x ) ## 1.XXXXX { my ( $quote, $linetime, $comment ) = ( $1, $2, $3 ); # captures my ( $snaghour, $snagminute, $snagsecond ) = split /:/, $linetime; + chop($quote); if (parsedate($snaghour.":".$snagminute.":".$snagsecond) <= parsed +ate($hour.":".$min.":00")) { $actualquote1 = $quote; } } } close(DATAFILE);
Now my problem is; The code works great when the script runs on the 30minute, $actualquote gets assigned as it should.

The issue is the 00 script run, $actualquote never gets assigned the value i would expect, it remains assigned to 0.

can anyone suggest what the issue is?

i have mulled over this problem for a while and came up with a really ugly hacked solution previously.

I am rewriting my code now and i am sure this type of approach is cleaner.

thanks for reading and i hope i make some sense.
conal.

In reply to Time::ParseDate issues by Conal

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.