drewboy has asked for the wisdom of the Perl Monks concerning the following question:
$found = 0; # Makes sure the record is in the database. open (DB, "<record.db") if ($db_use_flock) { flock(DB, 1); } LINE: while (<DB>) { (/^#/) and ($output .= $_ and next LINE); (/^\s*$/) and next LINE; chomp; @data = &split_decode($_); if ($data[$db_key_pos] eq $in{$db_key}) { # $db_key_pos re +fers to ID# in the database I think $output .= &join_encode(%in); $found = 1; } else { $output .= "$_\n"; # else print regular line. } } close DB; if ($found) { open (DB, ">record.db") if ($db_use_flock) { flock(DB, 2) } print DB $output; close DB; &site_html_modify_success; } else { &site_html_modify_failure; } } sub get_record { my ($key, $found, @data, $field); $key = shift; $found = 0; open (DB, "<record.db") if ($db_use_flock) { flock(DB, 1); } LINE: while (<DB>) { (/^#/) and next LINE; (/^\s*$/) and next LINE; chomp; @data = &split_decode($_); if ($data[$db_key_pos] eq $key) { $found = 1; %rec = &array_to_hash (0, @data); last LINE; } } close DB; $found ? (return %rec) : (return undef); } sub join_encode { my %hash = @_; my ($tmp, $col, $output); foreach $col (@db_cols) { $tmp = $hash{$col}; $tmp =~ s/^\s+//g; # Trim leading blanks... $tmp =~ s/\s+$//g; # Trim trailing blanks... $tmp =~ s/\Q$db_delim\E/~~/og; # Change delimeter to ~~ symbo +l. $tmp =~ s/\n/``/g; # Change newline to `` symbol. $tmp =~ s/\r//g; # Remove Windows linefeed char +acter. $output .= $tmp . $db_delim; # Build Output. } chop $output; # remove extra delimeter. $output .= "\n"; # add linefeed char. return $output; } sub split_decode { my ($input) = shift; my (@array) = split (/\Q$db_delim\E/o, $input, $#db_cols+1); foreach (@array) { s/~~/$db_delim/g; # Retrieve Delimiter.. s/``/\n/g; # Change '' back to newlines.. } return @array; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with database management
by trs80 (Priest) on Feb 19, 2002 at 07:20 UTC | |
|
Re: Help with database management
by princepawn (Parson) on Feb 20, 2002 at 05:14 UTC | |
|
Re: Help with database management
by Ryszard (Priest) on Feb 20, 2002 at 04:13 UTC | |
|
Re: Help with database management
by Xanatax (Scribe) on Feb 20, 2002 at 04:50 UTC | |
|
Re: Help with database management
by drewboy (Sexton) on Feb 20, 2002 at 19:17 UTC | |
by Xanatax (Scribe) on Feb 24, 2002 at 00:34 UTC |