Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^3: Time matching YYYY-MM-DD HH:MM:SS.SSS

by dave_the_m (Prior)
on Jul 26, 2012 at 19:03 UTC ( #983912=note: print w/replies, xml ) Need Help??

in reply to Re^2: Time matching YYYY-MM-DD HH:MM:SS.SSS
in thread Time matching YYYY-MM-DD HH:MM:SS.SSS

Well, I asked for code and data that demonstrates the inconsistency; you didn't show any data.

Having said that, your code is ... well .. just God-awful.

It violates just about every rule of good coding practice and style going. I haven't the will to go though a complete list (maybe some other kind soul will have the patience), but just for starters:


use warnings; use strict;
at the start of your code. You will be amazed!

The two-arg form of open is frowned upon. The one-arg form is vomit inducing.

In your second branch, you have $i = $i++; which is definitely not what you need, and may in fact be the cause of all your issues.


Replies are listed 'Best First'.
Re^4: Time matching YYYY-MM-DD HH:MM:SS.SSS
by PRyanRay (Novice) on Jul 26, 2012 at 19:19 UTC
    The $i = $i++ was a cut and paste error. That's not the problem. It should be $i++;. The data would look something like this:
    file1.txt: 2009/01/01 00:05:00.000 nmbr nmbr 2009/01/01 00:10:00.000 nmbr nmbr 2009/01/01 00:15:00.000 nmbr nmbr 2009/01/01 00:20:00.000 nmbr nmbr file2.txt: 2009/01/01 00:00:00.000 nmbr nmbr 2009/01/01 00:05:00.000 nmbr nmbr 2009/01/01 00:10:00.000 nmbr nmbr 2009/01/01 00:15:00.000 nmbr nmbr 2009/01/01 00:20:00.000 nmbr nmbr
    The user may not know which file contains the earlier timestamp. nmbr is a placeholder. Also, I didn't cut and paste the entire code, it is too long. I can include the preamble for you if you wish
    #!/usr/bin/perl use strict; use warnings;
    What is the form of open I should use? Thanks for the help.
      So: is what you want to do to count the number of (non-epoch) lines in the earlier file that are before the first date in the second file?

      Note that unless the first timestamp in the later file exactly matches one of the timestamps in the earlier file, your code will keep counting through the rest of the file.

      Use the 3-arg form with lexical filehandles:

      open my $fh, '<', 'newfile.txt' or die "Can't open newfile.txt: $!\n";
      If use warnings was in scope where you reference @Array0[0], you would have seen a warning (not that it affects the correct execution of your code).


        That is exactly correct. The timestamps will eventually match up. Essentially, one of the files may be a subset of the other. Each line has data that may be different for the same times. I need to compare that data. That part of the code is done. So, yes, I can count on the timestamps matching up once I get rid of the first n lines of the earlier file. What is the easiest (prettiest I guess) way to do this? Thanks a lot.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://983912]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2017-09-21 18:58 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (252 votes). Check out past polls.