blink has asked for the wisdom of the Perl Monks concerning the following question:

I'm having a hard time with this script. It needs to print the "Daily Window", unless the "Daily Window" is "00:00:00 - 24:00:00".

When run, the output of the code below is:

corpsrv2_archives runs on Monday 00:00:00 --> Monday 06:00:00 Tuesday 00:00:00 --> Tuesday 06:00:00 Wednesday 00:00:00 --> Wednesday 06:00:00 Thursday 00:00:00 --> Thursday 06:00:00 Friday 00:00:00 --> Friday 06:00:00 Saturday 00:00:00 --> Saturday 06:00:00 corpsrv2_finp_cold runs on Monday 00:00:00 --> Monday 06:00:00 Tuesday 00:00:00 --> Tuesday 06:00:00 Wednesday 00:00:00 --> Wednesday 06:00:00 Thursday 00:00:00 --> Thursday 06:00:00 Friday 00:00:00 --> Friday 06:00:00 Saturday 00:00:00 --> Saturday 06:00:00 corpsrv2_psoft_hot runs on Monday 00:00:00 --> Monday 06:00:00 Tuesday 00:00:00 --> Tuesday 06:00:00 Wednesday 00:00:00 --> Wednesday 06:00:00 Thursday 00:00:00 --> Thursday 06:00:00 Friday 00:00:00 --> Friday 06:00:00 Saturday 00:00:00 --> Saturday 06:00:00
Can anyone help me to sort out what I'm missing, here?
#!/usr/local/bin/perl -w use strict; my %data; my $sid; my $day; while (<DATA>) { next if (/Default/); if (/Policy Name:(\s+)(.*?)$/) { $sid = "$2"; next; } next unless (/(\s+)Daily Windows\:/ .. /(\s+)Schedule\:/); if (/(^\s+)(.*?day)/) { next if (/24|Week/); $day = $_; chomp $day; push @{$data{$sid}}, $day; } } foreach my $key (sort keys %data) { print "$key runs on\n"; foreach (@{$data{$sid}}) { print "$_\n"; } }
__DATA__ ------------------------------------------------------------ Policy Name: corpsrv2_archives Schedule: Full Type: Full Backup Maximum MPX: 1 Retention Level: 3 (1 month) Number Copies: 1 Fail on Error: 0 Residence: (specific storage unit not required) Volume Pool: (same as policy volume pool) Calendar sched: Enabled Thursday, Week 1 Friday, Week 1 Saturday, Week 1 Thursday, Week 2 Friday, Week 2 Saturday, Week 2 Thursday, Week 3 Friday, Week 3 Saturday, Week 3 Thursday, Week 4 Friday, Week 4 Saturday, Week 4 Thursday, Week 5 Friday, Week 5 Saturday, Week 5 Daily Windows: Sunday 06:20:00 --> Sunday 07:20:00 Monday 06:20:00 --> Monday 07:20:00 Tuesday 06:20:00 --> Tuesday 07:20:00 Wednesday 06:20:00 --> Wednesday 07:20:00 Thursday 06:20:00 --> Thursday 07:20:00 Friday 06:20:00 --> Friday 07:20:00 Saturday 06:20:00 --> Saturday 07:20:00 ------------------------------------------------------------ Policy Name: corpsrv2_finp_cold Schedule: corpsrv2_finp_cold Type: Automatic Full Backup Maximum MPX: 2 Retention Level: 3 (1 month) Number Copies: 1 Fail on Error: 0 Residence: (specific storage unit not required) Volume Pool: (same as policy volume pool) Calendar sched: Enabled Sunday, Week 1 Saturday, Week 1 Sunday, Week 2 Saturday, Week 2 Sunday, Week 3 Saturday, Week 3 Sunday, Week 4 Saturday, Week 4 Sunday, Week 5 Saturday, Week 5 Daily Windows: Saturday 22:00:00 --> Sunday 04:00:00 Schedule: Default-Application-Backup Type: Application Backup Maximum MPX: 2 Retention Level: 3 (1 month) Number Copies: 1 Fail on Error: 0 Residence: (specific storage unit not required) Volume Pool: (same as policy volume pool) Daily Windows: Sunday 00:00:00 --> Sunday 24:00:00 Monday 00:00:00 --> Monday 24:00:00 Tuesday 00:00:00 --> Tuesday 24:00:00 Wednesday 00:00:00 --> Wednesday 24:00:00 Thursday 00: Policy Name: corpsrv2_psoft_hot Schedule: corpsrv2_psoft_hot Type: Automatic Full Backup Maximum MPX: 2 Retention Level: 3 (1 month) Number Copies: 1 Fail on Error: 0 Residence: (specific storage unit not required) Volume Pool: (same as policy volume pool) Calendar sched: Enabled Friday, Week 1 Saturday, Week 1 Friday, Week 2 Saturday, Week 2 Friday, Week 3 Saturday, Week 3 Friday, Week 4 Saturday, Week 4 Friday, Week 5 Saturday, Week 5 Daily Windows: Monday 00:00:00 --> Monday 06:00:00 Tuesday 00:00:00 --> Tuesday 06:00:00 Wednesday 00:00:00 --> Wednesday 06:00:00 Thursday 00:00:00 --> Thursday 06:00:00 Friday 00:00:00 --> Friday 06:00:00 Saturday 00:00:00 --> Saturday 06:00:00 Schedule: Default-Application-Backup Type: Application Backup Maximum MPX: 2 Retention Level: 3 (1 month) Number Copies: 1 Fail on Error: 0 Residence: (specific storage unit not required) Volume Pool: (same as policy volume pool) Daily Windows: Sunday 00:00:00 --> Sunday 24:00:00 Monday 00:00:00 --> Monday 24:00:00 Tuesday 00:00:00 --> Tuesday 24:00:00 Wednesday 00:00:00 --> Wednesday 24:00:00 Thursday 00:00:00 --> Thursday 24:00:00 Friday 00:00:00 --> Friday 24:00:00 Saturday 00:00:00 --> Saturday 24:00:00

Edit by tye, add READMORE, missing >

Replies are listed 'Best First'.
Re: Matching lines between several other lines
by BrowserUk (Patriarch) on Jun 06, 2003 at 01:17 UTC

      foreach (@{$data{$sid}})

    If you use constant input, you'll get constant output:) Try:

      foreach ( @{ $data{ $key } } )

    And don't a few spaces make things easier to read? Of course, where you put the spaces is a whole other debate:)


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller