#!/usr/bin/perl -w # # Simple utility to read database from other shell scripts. # use strict; my $topdir="/huge/vids"; my $whodir="$topdir/DoctorWho"; my $dbdir="$whodir/.data"; my $dbfile="$dbdir/allinfo.txt"; my %db; # Get PATH set to include this script's directory and other useful bits my $newpath=`dirname $0`; chomp($newpath); $newpath=`$newpath/echo-path`; chomp($newpath); $ENV{'PATH'}=$newpath; # Read in the existing database. my $fh; my $r; if (open($fh, '<', $dbfile)) { while (<$fh>) { chomp; if (/^\[(.+)\]$/) { my $basename = $1; $r = {}; $db{$basename} = $r; } elsif (/^([A-Za-z0-9_]+)=(.+)$/) { if (defined($r)) { my $key = $1; my $val = $2; $r->{$key} = $val; } } } close($fh); undef($fh); undef($r); } if (scalar(@ARGV) != 2) { die "Usage: db-read key valuename\n"; } $r = $db{$ARGV[0]}; if (defined($r)) { my $val = $r->{$ARGV[1]}; if (defined($val)) { print "$val\n"; exit(0); } } exit(2);