in reply to How to read each line of file into an array and split contnts of each line into array cells

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

  • Comment on Re: How to read each line of file into an array and split contnts of each line into array cells
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: How to read each line of file into an array and split contnts of each line into array cells
by crazy-duck (Novice) on Oct 15, 2013 at 02:38 UTC
    Hi Ken

    Thank you for your response and appreciate all your efforts in helping here, for the above script can we amend to do a text comparision "**FAILED PROD**" that comes in between 6pm to 6am inclusive.

    Thank you cd
      "Thank you for your response and appreciate all your efforts in helping here,"

      You're welcome.

      "for the above script can we amend to do a text comparision "**FAILED PROD**" that comes in between 6pm to 6am inclusive."

      I don't understand this:

      • I don't know who you are referring to when you say "we".
      • If you're asking for some sort of permission to use/modify this code, you don't need to.
      • The code is already dealing with "6pm to 6am inclusive".

      -- Ken

        Hi Ken

        The script is pulling up all the details that is coming in between 6pm to 6am, But we need to capure on ly those that are starting with **FAILED PROD** between 6am to 6pm