in reply to Re: Flat file DB
in thread Flat file DB
Allow me to comment a little bit on your code, you are sometimes making your life harder than it has to be ;-) I will make the comments sequentially with the source code.
my $keyword = $ARGV[0] || die << "USAGE"; use: agenda keyword (databasefile separator pos.key) default database: $db_file default separator: $separator default pos.key: $pri and so on USAGE # the line above marks the end
Then perl appends automatically the line number where the error occured - very helpful for debugging. And don't worry, perl will put a newline at the end of the statement.open DB, "<$db_file" or die "Can't open $db_file: $!\n"; # leave out the final \n open DB, "<$db_file" or die "Can't open $db_file: $!";
is really unnecessary, both lines read exactly the same. There has been quite some discussion about commenting correctly here at PM, have a look with Super Search.### Close database close DB;
my $first_record = <DB>; chomp $first_record; # in one line chomp(my $first_record = <DB>);
print "\n ** keyword: $item\n\n"; # and print " $names[$features] = $values{$item}[$features]\n";
There are more things, e.g. I don't think the hash of arrays is the best datastructure for this task, you are not using the main feature of a hash, the direct access to an element by a key.
It has probably been some time since you wrote this script, your perl has improved in the meantime. So as a good exercise I'd suggest to rewrite the whole thing, rethinking your data structure and incorporating my advices. If you then post your script here you will get further suggestions for improvement. And at the end of the day you will have learnt a lot :-)
-- Hofmator
|
|---|