Perl DBMS

D

Dave

Hi,

I have a ikonboard messageboard ( which is written in perl), and I have all
the databases saved locally.

However they are in a *.db, *.dnt.db format, and i cannot access them via
the standard dbmopen(%hash, $database, 0666).

It simply creates a new file instead of accessing the current one.

I had a suspicion that the version of dbm on the server ( ie the one that
created the databases at the start) is a diffenent on to the one on my
windows machine.

So i copied the perl script to the server and tried to run it there - still
unsuccessfully.

Could not open message_data-115-1055789109 (Invalid argument) at read.pl
line 36.

( I removed the .db from the filename ).


Does anyone know what the problem is. I can post a sample database if
required.
Thanks
 
J

James Willmore

On Thu, 11 Sep 2003 22:22:33 +0100
Dave said:
Does anyone know what the problem is. I can post a sample database
if required.

No, but code would be helpful :)

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
[Sir Stafford Cripps] has all the virtues I dislike and none of
the vices I admire. -- Winston Churchill
 
G

Gunnar Hjalmarsson

Dave said:
I have a ikonboard messageboard ( which is written in perl), and I
have all the databases saved locally.

However they are in a *.db, *.dnt.db format, and i cannot access
them via the standard dbmopen(%hash, $database, 0666).

It simply creates a new file instead of accessing the current one.

I had a suspicion that the version of dbm on the server ( ie the
one that created the databases at the start) is a diffenent on to
the one on my windows machine.

Are you sure they are DBM files? Or can they be plain text files that
happen to have .db file extentions? (Have you tried to open one of
them with e.g. Notepad?)

If that doesn't help, you'd better do as James suggested and post some
code, such as a code fragment that creates or read the databases.
 
D

Dave

a    R  ?_?y 
 Ñh^ 



  ` þ`

1|^|1063198343|^|0|^|Hi|^|Hey there!  Hows
U?<br><br>Sarah|^|0|^|83-1054642790|^|Sarah
B|^||^||^|in|^|67-1054343639|^|67-1054343639|^|Chumiest crazy1

Here is one of the databases ( this is just copied and pasted after the file
was opened in notepad.

Thanks
 
G

Gunnar Hjalmarsson

ge0rge said:
which says '... they also agree that it's usually in bad taste to
correct mistakes publicly'

That was a quote out of context, which btw is bad everywhere.
Actually, the quoting style document describes various kind of
newsgroups, and to anybody who has followed _this_ group for a while,
it stands perfectly clear that you'd better expect public corrections
if you don't respect the posting guidelines.
MS is the principal culprit IMO, not the newbees.

May be true. But pointing out to a newbie that there are posting
guidelines is a way to help them benefit from this group. It does
_not_ make him/her a "culprit".
 
G

ge0rge

Gunnar Hjalmarsson said:
That was a quote out of context, which btw is bad everywhere.
Actually, the quoting style document describes various kind of
newsgroups, and to anybody who has followed _this_ group for a while,
it stands perfectly clear that you'd better expect public corrections
if you don't respect the posting guidelines.

Out of context? Perfectly clear to me. Here's another quote then - 'This
document is a description of the traditionally accepted "quoting style" in
Usenet newsgroup postings. Please do not consider this to be a "regulatory"
document ("Thou shalt do it this way because we say so!") ...'
May be true. But pointing out to a newbie that there are posting
guidelines is a way to help them benefit from this group. It does
_not_ make him/her a "culprit".

I never said the newbie was culpable. MS is. Don't blame the users, fix the
code - as the saying goes. My IT colleagues who together amongst themselves
must have umpteenth years of computing experience also always top post their
emails. I've learnt to be unconcerned by such a pecadillo. The content is
more important than the form.

BTW, you do realise this is a bit of a wind up.

ge0rge
 
D

Dave

#!/usr/bin/perl

print "Content type:text/html\n\n";

my $path = `pwd`;
chomp $path;

opendir(DIR, $path) || print "Could not open $path";
@files = grep { /\.db$/ } readdir(DIR);
closedir(DIR);

my $new_file ="";
my @databases;

foreach $file (@files){

@info = split(/\./, $file, 2);


if($info[0] ne $new_file){

push(@databases, $info[0]);
}

$new_file = $info[0];


}

#!/usr/bin/perl

print "Content type:text/html\n\n";

my $path = `pwd`;
chomp $path;

opendir(DIR, $path) || print "Could not open $path";
@files = grep { /\.db$/ } readdir(DIR);
closedir(DIR);

my $new_file ="";
my @databases;

foreach $file (@files){

@info = split(/\./, $file, 2);


if($info[0] ne $new_file){

push(@databases, $info[0]);
}

$new_file = $info[0];


}



foreach $file (@databases){

print "$file\n\n";

dbmopen(%hash, $file, 0666) || print "Could not open $file ($!)";

## $! gives the error "Invalid Argument"

foreach $key (keys %hash){

print "$key : $hash{$key}\n";
}

dbmclose(%hash);

}

Ok heres my code. ( sorry that i didnt reply to the requested messages - the
original posts have dissapeared from Outlook!)

Dit not make sense to top post, thus meaning that u dont have to scroll
through pages and pages of stuff just to get the info you want!

Thanks
 
G

Gunnar Hjalmarsson

ge0rge said:
Out of context? Perfectly clear to me. Here's another quote then -
'This document is a description of the traditionally accepted
"quoting style" in Usenet newsgroup postings. Please do not
consider this to be a "regulatory" document ("Thou shalt do it this
way because we say so!") ...'

Dear George,

Do you have any particular reason for questioning my simple pointer
about top posting?

You'd better study the posting guidelines for _this group_ before
starting a discussion like this. The clpmisc guidelines at
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html,
which express the consensus of _this_ group, say:

"Intersperse your comments *following* each section of quoted
text to which they relate. Unappreciated followup styles are
referred to as "Jeopardy" (because the answer comes before the
question), or "TOFU".

Reversing the chronology of the dialog makes it much harder to
understand (some folks won't even read it if written in that
style). For more information on quoting style, see:

http://web.presby.edu/~nnqadmin/nnq/nquote.html "

In other words, the purpose with referring to the general document
about quoting style is to _further explain_ the reason why that
particuar rule is applied in this group.
My IT colleagues who together amongst themselves must have
umpteenth years of computing experience also always top post their
emails.

Emails is one thing, Usenet groups is another.
I've learnt to be unconcerned by such a pecadillo. The content is
more important than the form.

Then you belong to the minority here. The consensus of _this_ group is
pretty clear. Please respect that.
 
A

Alan J. Flavell

Out of context? Perfectly clear to me. Here's another quote then - 'This
document is a description of the traditionally accepted "quoting style" in
Usenet newsgroup postings. Please do not consider this to be a "regulatory"
document ("Thou shalt do it this way because we say so!") ...'

Indeed. The advice is to do it not because the FAQ or RFC says you
must, but because the body of other serious participants expect it,
and when they killfile you for ignoring the social mores of the group,
you'll be lucky if one of them bothers to tell you about it.

There was (and may still be, for all that I know) an FAQ for
microsoft.* groups which instructs participants to snip the quotage to
the minimum needed for setting context, and place their responses
after the relevant quoted parts. Does that sound familiar? For big-8
usent groups, that is even more the expectation. As for other
hierarchies, I recall an FAQ for alt.english.usage which explained to
its participants that OE placed the cursor at the top of the quoted
material because that was the natural place to start snipping
irrelevant comments before placing one's responses below the relevant
quoted parts to which one referred. Sounds familiar?
BTW, you do realise this is a bit of a wind up.

Oh yes.

Did I mention that the best adjunct to participating in usenet is a
well-tended killfile?
 
T

Tad McClellan

ge0rge said:
My IT colleagues who together amongst themselves
must have umpteenth years of computing experience also always top post their
emails.


email is not usenet. It is a different dynamic entirely.
 
E

Eric Bohlman

#!/usr/bin/perl

Name the two things missing here...
print "Content type:text/html\n\n";

my $path = `pwd`;
chomp $path;

opendir(DIR, $path) || print "Could not open $path";
@files = grep { /\.db$/ } readdir(DIR);
closedir(DIR);

You know, don't you, that @files will contain *only* the base names of the
matching files, *not* their full paths?
my $new_file ="";
my @databases;

foreach $file (@files){

@info = split(/\./, $file, 2);


if($info[0] ne $new_file){

push(@databases, $info[0]);
}

$new_file = $info[0];


}

Why are you making separate passes over arrays, instead of doing this
filtering as you read the filenames?
foreach $file (@databases){

print "$file\n\n";

dbmopen(%hash, $file, 0666) || print "Could not open $file ($!)";

Uh oh. Remember that bit about not having the full path names?
 
G

Gunnar Hjalmarsson

Dave wrote:

Ok heres my code.

It includes some errors, and Eric pointed out some of those.

I think you need to read up on DBM files, the fact that there are
different kinds, etc. A start may be
http://search.cpan.org/author/JHI/perl-5.8.0/lib/AnyDBM_File.pm

From the code you posted it seems as if the data is stored in
Berkeley format, and the DB_File module and/or the Berkeley DB library
is probably not installed on your Windows box.

Below follows some code that reads .db files, prints the contents, and
saves the data as SDBM databases. SDBM is portable between Unix and
Windows, and each database consists of two files with .dir respective
..pag extensions.
Dit not make sense to top post, thus meaning that u dont have to scroll
through pages and pages of stuff just to get the info you want!

Please study the messages about top posting more carefully. ;-)

# Code starts here

#!/usr/bin/perl
use strict;
use warnings;
use CGI::Carp 'fatalsToBrowser';
use DB_File;
use SDBM_File;
use Fcntl;

print "Content-type: text/html\n\n";

my $path = `pwd`;
chomp $path;

opendir DIR, $path or die "Could not open $path\n$!";
my @files = grep { /\.db$/ } readdir DIR;
closedir DIR;

foreach my $file (@files) {
tie my %hash, 'DB_File', "$path/$file", 0666
or die "Couldn't open... $!";

print "$_ : $hash{$_}\n" for keys %hash;

# Copy data to SDBM
tie my %hash2, 'SDBM_File', "$path/".(substr $file, 0, -3),
O_CREAT | O_RDWR, 0666 or die "Couldn't open... $!";
%hash2 = %hash;
untie %hash2;

untie %hash;
}

# Code ends here

Hope that helps!
 
J

Jay Tilton

: My IT colleagues who together amongst themselves
: must have umpteenth years of computing experience also always top post their
: emails.

The first rule of writing is to write for the audience. The audience in
clpm prefers articles that meet certain style expectations. Whatever
goes on in other newsgroups, in email, or among your colleagues is
irrelevant.

: The content is more important than the form.

Then why do novels, proposals, screenplays, instruction manuals, and
musical scores all have distinct and recognizable forms?

In a forum like clpm, presentation can be more important than content,
since readers are not at all obliged to be interested in what an author
has to say. Cooperation is a matter of pragmatism. Make readers work
at figuring out what you're saying and they're less likely to work at
helping.
 
T

Tom

ge0rge said:
Out of context? Perfectly clear to me. Here's another quote then - 'This
document is a description of the traditionally accepted "quoting style" in
Usenet newsgroup postings. Please do not consider this to be a "regulatory"
document ("Thou shalt do it this way because we say so!") ...'
..
..

Well, you know what they say, when in Rome do as the Romans do.

Tom
ztml.com
 
D

Dave

Eric Bohlman said:
Name the two things missing here...

I guess u mean -w ??
print "Content type:text/html\n\n";

my $path = `pwd`;
chomp $path;

opendir(DIR, $path) || print "Could not open $path";
@files = grep { /\.db$/ } readdir(DIR);
closedir(DIR);

You know, don't you, that @files will contain *only* the base names of the
matching files, *not* their full paths?
Yup
my $new_file ="";
my @databases;

foreach $file (@files){

@info = split(/\./, $file, 2);


if($info[0] ne $new_file){

push(@databases, $info[0]);
}

$new_file = $info[0];


}

Why are you making separate passes over arrays, instead of doing this
filtering as you read the filenames?

What other way can i do this?
Uh oh. Remember that bit about not having the full path names?

I know this is bad programming practice, but for now I'm running the script
in the same directory as the databases ( just till i get the thing
working). But that dosnt explain why I get the error below. If the path was
wrong then the dbm would create a new database with that name in the same
directory as the script (if the script WAS in a different dir), but instead
it says "Invalid Argument".
 
G

ge0rge

<OT>

Alan J. Flavell said:
Indeed. The advice is to do it not because the FAQ or RFC says you
must, but because the body of other serious participants expect it,
and when they killfile you for ignoring the social mores of the group,
you'll be lucky if one of them bothers to tell you about it.

Well, that would be a bit of an overkill. Don't you think so? Killfiling
someone because (s)he top post!
There was (and may still be, for all that I know) an FAQ for
microsoft.* groups which instructs participants to snip the quotage to
the minimum needed for setting context, and place their responses
after the relevant quoted parts. Does that sound familiar? For big-8
usent groups, that is even more the expectation. As for other
hierarchies, I recall an FAQ for alt.english.usage which explained to
its participants that OE placed the cursor at the top of the quoted
material because that was the natural place to start snipping
irrelevant comments before placing one's responses below the relevant
quoted parts to which one referred. Sounds familiar?

Can't understand why people (meaning us all, I guess) are so accommodating
with MS and are prepared to make excuses or go through all sort of
contortions to work with their software when clearly it is a stupid idea to
place the cursor at the top. At the very least, they could have put an
option to allow for the placement of the cursor.
Oh yes.

Did I mention that the best adjunct to participating in usenet is a
well-tended killfile?

Whoaa! That's a bit below the belt. It was just a bit of harmless banter to
test the water in this NG.
BTW, I think the whole idea of a killfile is another OTT response to
something not worth a second thought... but then again there's no accounting
for what people feel passionate about.

Anyway, I shall do as suggested by another poster - when in Rome ... ('cos
top posters drive me nuts (well, rarely!)).

Now, time for me to shut up and start lurking awhile in this NG until I have
something worthwhile to ask or say!

</OT>

ge0rge
 
T

Tad McClellan

Dave said:
I guess u mean -w ??


The warnings pragma is better than the command line switch variety.

The two things are:

use strict;
use warnings;


Have you seen the Posting Guidelines that are posted here frequently?
 
T

Tad McClellan

ge0rge said:


But it isn't.

Where else but clpmisc would be appropriate for discussing
the goings-on in clpmisc?

Such "administration" threads are annoying/wasteful, but not off-topic.



[snip: about top-posting]

Well, that would be a bit of an overkill. Don't you think so?


Whether it is "right" or "best" is irrelevant (unless you think
you can change everyone's mind).

What matters in a pragmatic sense is that it happens here.

So if you want the widest readership for articles posted here, it
is worth a bit of effort to avoid stepping on killfile "mines".

Using an upside-down posting style is but one variety of mine.

The Posting Guidelines attempt to steer folks away from
many of the most common varieties...

Killfiling
someone because (s)he top post!


I have:

% Jeopardists
Score:: -9998
< 37 addresses so far >


None of them for top-posting once or twice.

All of them people who complain about it once corrected, or
insisted on continuing with reversing time.

Whoaa! That's a bit below the belt.


I don't know what you saw there, but I don't see a "blow"
landed anywhere.

Did you see something personal there?

Sounds like merely a description of clpmisc reality to me...

It was just a bit of harmless banter to
test the water in this NG.


If you slap a junk yard dog to see if he is mean, you should be
prepared to pay with your hand (or worse). :)

BTW, I think the whole idea of a killfile is another OTT response to


How to not be ignored in clpmisc is on-topic for clpmisc.

Now, time for me to shut up and start lurking awhile in this NG


Perhaps you cannot understand the wide spread use of killfiles
because your experiences are different from the killfiler's
experiences.

Lurking for a few years will help give you insight there. :)

Most of the frequent-answers are busy folks. That's how they gain
enough expertise to be able to answer questions!

They undoubtedly have a "Perl time" budget and clpmisc is likely
only one of the (less-important) places that that time is spent. They're
busy writing modules, reading mailing lists, etc as well as
donating time here.

When they get in a budget crunch, they can stop reading clpmisc
or they can find a way to spend less time while reading clpmisc.

Many wonderful question-answerers have already chosen the
former approach. :-(

I've had my code corrected here by Larry Wall himself. That won't
be happening anymore. :-( :-(

So, these type of people who _are_ still here, are very likely to
have implemented the later approach, ie. they use heuristics
(scorefiles) to help reduce their workload.


This is a high traffic newsgroup, often 200 posts a day.

Nobody reads all of them, so they must "filter" them somehow.

Whether they do it manually or automatically does not make much
difference, they must be skipping a whole lot of articles either way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top