G'day crazy-duck,
Welcome to the monastery.
You should set up dummy data to test your solution.
That data should include boundary conditions (e.g exactly 6am, 1 minute before, and 1 minute after).
You also need to be clearer about the range: "between 6pm to 6am" inclusive? exclusive? other?
In the code you posted, there's some problems:
-
See the open documentation for the preferred way to open a file for reading.
Something like: open my $fh, '<', $filename ...
-
while (<FILE>) (which would become while (<$fh>)) reads a record at a time.
Given you're reading a (potentially very long) log file, this is a good idea.
-
After reading the first record, you read all the remaining records into an array with @ARRAY = <FILE>.
This is a bad idea for the same reason that reading a record at a time was a good idea.
Also, as there's now no more records to read, the while loop won't reiterate (i.e. in total, it only loops once).
-
There's some garbage in the close FILE line. Possibly a typo; however, you need to post exactly the code you're running: we can't guess what you meant to write. See the close documentation, if necessary.
Identifying the lines you want is fairly straightforward.
For something this simple, I wouldn't recommend a CPAN module nor a complex calculation.
A plain comparison, which is easy to read and, if necessary, easy to adjust, is all that's required.
#!/usr/bin/env perl
use strict;
use warnings;
while (<DATA>) {
my ($time, $hours, $mins) = /@((\d\d):(\d\d))/;
next unless $hours < 6 || $hours > 17 || $time eq '06:00';
# A line we want is in $_ - process it here, e.g.
print;
}
__DATA__
**FAILED PROD** - BUGS - 08/26/13 @00:00 - ... WANTED 1
**FAILED PROD** - BUGS - 08/26/13 @00:01 - ... WANTED 2
**FAILED PROD** - BUGS - 08/26/13 @05:59 - ... WANTED 3
**FAILED PROD** - BUGS - 08/26/13 @06:00 - ... WANTED 4
**FAILED PROD** - BUGS - 08/26/13 @06:01 - ... NOT WANTED 1
**FAILED PROD** - BUGS - 08/26/13 @12:00 - ... NOT WANTED 2
**FAILED PROD** - BUGS - 08/26/13 @17:59 - ... NOT WANTED 3
**FAILED PROD** - BUGS - 08/26/13 @18:00 - ... WANTED 5
**FAILED PROD** - BUGS - 08/26/13 @18:01 - ... WANTED 6
**FAILED PROD** - BUGS - 08/26/13 @23:59 - ... WANTED 7
**FAILED PROD** - BUGS - 08/26/13 @24:00 - ... WANTED 8 (LAST)
Output:
**FAILED PROD** - BUGS - 08/26/13 @00:00 - ... WANTED 1
**FAILED PROD** - BUGS - 08/26/13 @00:01 - ... WANTED 2
**FAILED PROD** - BUGS - 08/26/13 @05:59 - ... WANTED 3
**FAILED PROD** - BUGS - 08/26/13 @06:00 - ... WANTED 4
**FAILED PROD** - BUGS - 08/26/13 @18:00 - ... WANTED 5
**FAILED PROD** - BUGS - 08/26/13 @18:01 - ... WANTED 6
**FAILED PROD** - BUGS - 08/26/13 @23:59 - ... WANTED 7
**FAILED PROD** - BUGS - 08/26/13 @24:00 - ... WANTED 8 (LAST)
-
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.