newbie stuck in a HOA

pmd_at_unex.berkeley.edu
Date: 10/05/04


Date: Tue, 5 Oct 2004 13:32:49 -0700 (PDT)
To: beginners@perl.org

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 = \@edp_cancel;
        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



Relevant Pages

  • RE: Forms with Options?
    ... 'Cancel' a RuntimeError 3131 and Syntax error shows up. ... If your excel file does not have then, ... spreadsheet to a database, Access will create 2 other error tables. ...
    (microsoft.public.access.formscoding)
  • =?Utf-8?Q?Re:_Canceling_and_deleting_a_rec?= =?Utf-8?Q?ord_via_code_=E2=80=93_help_please.?=
    ... The database was designed to allow the entry of intake lots of fruit and has ... As I mentioned in my original post the data entry has already been started ... the earliest harvest date I open an error form and display an error message. ... and if you cancel the event the record doesn't get saved. ...
    (microsoft.public.access.modulesdaovba)
  • Re: newbie stuck in a HOA
    ... > I have a flatfile database that contains information about ... > it is in the cancel file. ... @edp, and then $edp, even that's ok, but it still likely to make ... (still in the foreach loop of @cancel_list) ...
    (perl.beginners)
  • Re: Module Not Found
    ... Close the database. ... Still in the code window, choose Compile from the Debug menu. ... The error message could be related to something else that is going on, ... VB and press the cancel button I receive the error message ...
    (microsoft.public.access.formscoding)
  • Re: How to change bound continuous form with required fields
    ... that users want to get some of the data from outside the database. ... One option may be to use the Before Update event for notification only. ... That is, don't cancel, and don't undo. ... No need to wait for the Unload event. ...
    (microsoft.public.access.forms)