Gossamer Forum
Home : General : Perl Programming :

modifying several records

Quote Reply
modifying several records
i have some code that will manipulate some fields in a record by looking up data in a separate db when i modify a single record. it works fine. i'm trying to do the same thing when i am modifying several records at once. what i want is -- as it processes each record to modify, it does my routine to replace certain fields before it checks that all the fields are ok.

this is my code when i modify a single record -- it works:

Code:
sub modify_record {
my ($status, $line, @lines, @data, $output, $found, %rec, $key, $num_files, @files, $file, $file_test);
my ($message, $col, $i);

&before_modify_record;
$status = &validate_record;
blah blah blah
}

sub before_modify_record {
# --------------------------------------------------------
# populates some exhibit fields from the venue db

&switch_to_venue("venues");
%rec2 = &get_record2($in{'Venue'});
$in{'Exhibit_open'} = $rec2{'Exhibit_open'};
$in{'Exhibit_close'} = $rec2{'Exhibit_close'};
$in{'Venue_name'} = $rec2{'Venue_name'};
$in{'Exhibit'} = $rec2{'Venue_name'} . ' ' . $rec2{'Exhibit_open'} . ' - ' . $rec2{'Exhibit_close'};
}

this is what i'm trying to do when i have multiple records. the modification of multiple records works fine except when i try to call my sub to get the venue stuff

Code:
sub modify_mult_record {
# --------------------------------------------------------
# This routine will update multiple records at once. It expects
# to find in %in a series of records to update. They will be of the
# form field_name-key.
#
my ($key, %modify_list, %modify_rec, $rec_to_modify, @data, $key,
$errstr, $succstr, $output, %errors, $message);

# First let's pick which records to modify and then separate them and store
# them in their own hashes.
$rec_to_modify = 0;
foreach $key (keys %in) { # Build a hash of keys to modify.
if ($in{$key} eq "modify") {
$modify_list{$key} = 1;
$rec_to_modify = 1;
}
($key =~ /^(.*)-(.+)$/) and (${$modify_rec{$2}}{$1} = $in{$key});
}
# Choke if we don't have anything to do.
$rec_to_modify or (&html_modify_failure("no records specified.") and return);

open (DB, "<$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
(/^#/) and ($output .= $_ and next LINE);
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
$key = $data[$db_key_pos];

# Now we check if this record is something we want to modify. If so, then
# we make sure the new record is ok, if so we replace it.
if ($modify_list{$key}) {

@data = &before_modify_multi_record(@data); #### here's the problem, i've tried several different things

$status = &validate_multiple_records(%{$modify_rec{$key}});
blah blah blah
}

sub before_modify_multi_record { # 02/01/2011
# --------------------------------------------------------
# populates some exhibit fields from the venue db

my (@record) = @_;
&switch_to_venue("venues");
%rec2 = &get_record2($record[23]);
$record[3] = $rec2{'Exhibit_open'};
$record[4] = $rec2{'Exhibit_close'};
$record[2] = $rec2{'Venue_name'};
$record[30] = $rec2{'Venue_name'} . ' ' . $rec2{'Exhibit_open'} . ' - ' . $rec2{'Exhibit_close'};
return (@record);
}

i'm sure it's something simple, but i'm not too good passing stuff back and forth. thanks!
Subject Author Views Date
Thread modifying several records delicia 8884 Feb 1, 2011, 8:18 AM
Thread Re: [delicia] modifying several records
Andy 8623 Feb 1, 2011, 8:52 AM
Thread Re: [Andy] modifying several records
delicia 8639 Feb 1, 2011, 9:56 AM
Thread Re: [delicia] modifying several records
Andy 8584 Feb 1, 2011, 9:58 AM
Thread Re: [Andy] modifying several records
delicia 8556 Feb 1, 2011, 10:34 AM
Thread Re: [delicia] modifying several records
Andy 8616 Feb 1, 2011, 10:53 AM
Thread Re: [Andy] modifying several records
delicia 8558 Feb 1, 2011, 11:19 AM
Thread Re: [delicia] modifying several records
delicia 8518 Feb 1, 2011, 1:33 PM
Post Re: [delicia] modifying several records
Andy 8539 Feb 2, 2011, 1:12 AM