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:
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)
-- Ken
In reply to Re: How to read each line of file into an array and split contnts of each line into array cells
by kcott
in thread How to read each line of file into an array and split contnts of each line into array cells
by crazy-duck
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |