Hi All,

I am trying to extract a name that may have 0 or more keywords followed by comma separated values (or a job definition in TWS terms). The biggest problem for me is that they cross over multiple lines (example below). What I'm trying to do is make an array containing a hash with the name being the key and all of the keywords and comma separated values as the value. I seem to have it figured out for the section between SCHEDULE and : because I have only one name but after that I'm not sure what to do. The name does not always start in the same position and several records contain tabs instead of spaces. I was thinking about making it 1 long string but I don't know how to grab that last item following the comma. Any ideas?



*Added JPN_SD_DW_#.@ as dependency per Denise Oneto Request. Remedy Case#
*284335. 4/18/02 Paco.
*Added Job_Load_Financial_Backlog : Non_critical: remedy 314837 9/26/02 AMP.
*Added Z_ZDW00032_ZDW00032_GBL : Critical Todd Pardi 1/10/03

SCHEDULE D50_500#EUR_SD_DW_1
         ON      MO, TU, WE, TH, FR
         AT      1900
         CARRYFORWARD
         FOLLOWS EUR_SD_1.Z_ZSNAST00_EDC,
                 JPN_SD_DW_3.@
:
   PRD001#Z_ZDW00032_GBL_WEBM
   PRD001#Z_ZDW00003_EDC_WEBM
         FOLLOWS Z_ZDW00002_EDC_WEBM
   PRD001#Z_ZDWENTIT_TEST_WEBM
            AT      0000
            EVERY   30
            UNTIL   1200 +1 DAYS
   PRD007#JOB_LOAD_FINANCIAL_BACKLOG
         FOLLOWS Z_ZDWENTIT_TEST_WEBM
   PRD007#DAILY_AB_EDC
         FOLLOWS Z_ZDW00032_GBL_WEBM,
                 Z_ZSIODWCU_EDC_WEBM,
                 Z_ZDW00001_EDC_WEBM,
                 Z_ZDW00002_EDC_WEBM
END

my code so far:
#!/usr/bin/perl -w

use strict;
no strict 'refs';
use vars qw($dep $job);
my %keylist;
## Define keywords
my %keywords =(ASTERISK => '*', AT => 'AT', CARRYFORWARD => 'CARRYFORWARD', CONFIRMED => 'CONFIRMED',
               END => 'END', EVERY => 'EVERY', EXCEPT => 'EXCEPT', FOLLOWS =>'FOLLOWS',
               FREEDAYS => 'FREEDAYS', IN_ORDER => 'IN ORDER', KEYJOB => 'KEYJOB',
               KEYSCHED => 'KEYSCHED', LIMIT => 'LIMIT', NEEDS => 'NEEDS', ON => 'ON',
               OPENS => 'OPENS', PRIORITY => 'PRIORITY', PROMPT => 'PROMPT', SCHEDULE => 'SCHEDULE',
               UNTIL => 'UNTIL');
## End Define keywords
my @AoH;
my %hash = ( sched_name => '', critical => '', primary => '', alternates => '',
          group_email => '', FREEDAYS => '', ON => '', EXCEPT => '',
          AT => '', FOLLOWS => '', CARRYFORWARD => '', IN_ORDER => '', LIMIT => '',
          NEEDS => '', OPENS => '', PRIORITY => '', PROMPT => '',
          UNTIL => '', jobs => '' );
my %jhash = ( job_name =>'', follows =>'', at =>'', every =>'', until =>'', needs =>'',
             opens =>'', priority =>'', prompt =>''            
            );
### get files of schedule names
my $base="C:\\Docume~1\\pardit~1.PER\\MyDocu~1\\Maestro\\skeds";
opendir(DUR, "$base") || die "can't opendir $base: $!";
    my @files = grep { /[^\.]/ && -f "$base/$_" } readdir(DUR);
    closedir DUR;
## End files of schedule names

SCHEDULE: foreach(@files) {
    my $do='sched';
    chomp($_);
    $hash{shed_name}=$_;
    my @jobs;
    open(FH, "$base/$_");
LIST:    while(<FH>) {
         s/^\s+//;
         s/\s+$//;
         s/\*/ASTERISK /g;
         s/IN ORDER/IN_ORDER/;
         next LIST if(/^$/);
         chomp($_);
         #next SCHEDULE if(/^END$/);
         &comment($_) if(/^ASTERISK/);
         $do = 'job' if(/^:$/);
         #$pointer=$_;
         if($do eq 'sched') {
         &do($_);
         } else {
            push(@jobs, $_);
         }
         if(/^END$/) {
            &do(@jobs);
         }
       
    }# End LIST opening while
   
   
   
} #End Schedule

######### SUBS ##############

sub comment {
    my $self = shift;
    chomp($self);
    my ($type, $style);
    $self =~ s/^\s+//;
    $self =~ s/\s+$//;
    if ($self =~ /Primary:(.*)O:/) {
    $type=$1;
    $type =~s/^\s+//;
    $type =~ s/\s+$//;
    $style='primary';
    $hash{primary}=$type unless ($type eq '');
    }elsif ($self =~ /Secondary:(.*)O:/) {
        $type=$1;
        $style='alternates';
        $type =~s/^\s+//;
        $type =~ s/\s+$//;
        if (exists $hash{alternates}) {
            $hash{alternates}.=",$type" unless ($type eq '');
            }else {
            $hash{alternates}="$type" unless ($type eq '');
            }
    }elsif ($self =~ /Critical:(.*)/) {
        my $typ=$1;
        my $tap;
        ($type, $tap) = split(' ', $typ);
        $style='critical';
        $hash{critical}=$type unless ($type eq '');
    }elsif ($self =~ /List:(.*)O:/) {
        $type=$1;
        $style='alternates';
        $type =~s/^\s+//;
        $type =~ s/\s+$//;
        if (exists $hash{alternates}) {
            $hash{alternates}.=",$type" unless ($type eq '');
            }else {
            $hash{alternates}="$type" unless ($type eq '');
            }
    }elsif ($self =~ /Group:(.*)/) {
        $type=$1;
        $type =~s/^\s+//;
        $type =~ s/\s+$//;
        $style='group_email';
        $hash{group_email}=$type unless ($type eq '');
    }else {
        $type='';
        $style='none';
    }
    $type =~s/^\s+//;
    $type =~ s/\s+$//;
   
    unless($type eq '') {
    my $out="$type!$style";
    return $out;
    } else {
        $type = 'none';
    return "!$type";
    }
       
} # End comment

sub sched {
    my $point;
    my $self=shift;
    $self =~/(.*)\W (.*)/;
    my $test=$1;
    my $val=$2;
    if($keywords{$test}) {
        $hash{$test}=$val;
    }else {
        $hash{$test}.=$val;
    }
                         
   
}

sub job {
    my $point=shift;
    my $self=shift;
    if($self =~ /,/) { $dep='follow'; }
    $self =~/(.*)\W (.*)/;
    my $test=$1;
    my $val=$2;
    $jhash{job_name}=$self;
    if($keywords{$test}) {
        $jhash{$test}=$val;
    }else {
        $jhash{$test}.=$val;
    }
                         
   
}

Thank you,
Todd Pardi
Unix Applications Engineer
Systems Management
_______________________________________________
Perl-Unix-Users mailing list
Perl-Unix-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to