Hi all,

I have a flatfile database (falldata.tmp) that contains information about
all the courses offered
this includes: course number, course title, start date, day of week,
location, html link, section number, fee1, fee2, and status.

I have another file (cancel.txt) which contains a list of the courses that
are canceled.

What I want to do is change the status to "C" in the flatfile database, if
it is in the cancel file.

The problem I'm having is that
I'm getting duplicate results and also incorrect results as the code isn't
distinguishing between a canceled class and one that's not.


Any ideas on where I'm going wrong.
Thanks in advance,
Pam


sample data:
028076|Beginning Acting I|Sept 18|Sat|San Francisco|028086.html|1|275|0||


results:
OKAY 028860 ------------------
0: Impressionism: The Poetry of the Passing Moment
1: Oct 6
2: Wed
3: San Francisco
4: 028860.html
5:
6: 395
7: 0
8:


OKAY 028860 ------------------
0: Impressionism: The Poetry of the Passing Moment
1: Oct 6
2: Wed
3: San Francisco
4: 028860.html
5:
6: 395
7: 0
8:

CANCEL 028837 -----------------
0: Art, Architecture, and Culture of Cuba
1: Sept 13
2: Mon
3: Berkeley
4: 028837.html
5:
6: 365
7: 0
8: C


OKAY 028837 ------------------
0: Art, Architecture, and Culture of Cuba
1: Sept 13
2: Mon
3: Berkeley
4: 028837.html
5:
6: 365
7: 0
8: C




here's the code:
#!/usr/bin/perl -w
#Purpose update catalog database with C for cancel
use strict;

#make a backup
#system `cp /dept/unxmkt/www/cgi-bin/catalog/fall.txt ./falldata.bak`;
#system `cp /dept/unxmkt/www/cgi-bin/catalog/fall.txt ./falldata.tmp`;

#declare global variables
my $aref= "";

get_cancel();
add_cancel($aref);


#open file of canceled courses, push it on array @edp_cancel
sub get_cancel{
        my (@edp_cancel, $edp_cancel, $item, $status);
        open(CANCEL, "cancel.txt") or die("no cancelfile: ");

                while( defined($_= <CANCEL>) ){
                        chomp($_);
                        ($edp_cancel, $status) = split(/\|/, $_);
                        push @edp_cancel, $edp_cancel;
                }

        #use array reference in order to return a value
        $aref = [EMAIL PROTECTED];
        return $aref;
        close CANCEL;
} #end get_cancel


sub add_cancel{
#opens up copy of database, and splits data
#if match on edp adds "C" to database in status field

        my (%course_info, $course_info, $item, @edp, $edp, $course, $start, $day,
$loc, $link, $sec, $fee1, $fee2, $status, $cancel_edp, $i);

        #DEBUG
        #for my $cancel_edp(@{$aref}){
                #print("$cancel_edp ");
        #}

        open(TEMP, "falldata.tmp") or die("no temp file: ");

        while( defined($_ = <TEMP>) ){
                #split up the fields
                ($edp, $course, $start, $day, $loc, $link, $sec, $fee1, $fee2, $status)
= split(/\|/,

$_);

                #put course info into hash of array with edp the key
                $course_info{$edp} = [$course, $start, $day, $loc, $link, $sec, $fee1,
$fee2, $status];

        } #end while

        #DEBUG
        #foreach $item ( keys %course_info) {
                #print("$item: @{ $course_info{$item} }\n");
        #}



        #loop through all the courses in db
        #if edp matches a canceled edp, change status to C (cancel)
        foreach $item (keys %course_info){
                foreach $cancel_edp( @{$aref} ){
                        if($item == $cancel_edp){
                                #change the status to canceled
                                $course_info{$item}[8] = "C";

                                print("\n\nCANCEL $item --------------\n");
                                for $i (0 .. $#{ $course_info{$item} } ){
                                        print("$i: $course_info{$item}[$i]\n");
                                }

                        }


                        else{
                                print("\n\nOKAY $item ----------------\n");
                                for $i (0 .. $#{ $course_info{$item} } ){
                                        print("$i: $course_info{$item}[$i]\n");
                                }

                        }
                } #end foreach of the canceled courses
        } #end foreach of the courses in the db

        close TEMP;
} #end add_cancel




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to