PERL bug using sort with MLDBM? 
Author Message
 PERL bug using sort with MLDBM?

Hi,

I think I've stumbled across a PERL bug while using
the sort function - can someone confirm this?

I read through perlfunc which referred to problems
with qsort, although it didn't suggest how to
resolve issues.

The problem occurs when I try to sort using a
reference to a multi-level DBM file (MLDBM module) -
I get a 'Segmentation Fault (core dumped)'.

I tested exactly the same method using in-memory
multi-level hash tables and didn't experience
the problem.

I'm including two test scripts for each scenario,
i.e. i) in memory hashes and ii) using MLDBM, with
the associated output.

Note that I also tested the scipt using GDBM_File
and DB_File to ensure that I wasn't running out of
record-space in the DBM file. I got exactly
the same result.

Also note that with only two "fields", it didn't
exhibit the problem, which is why I have included
all my fields in the example.

Platform info:

SunOS kandinsky 5.5.1 Generic_103640-12 sun4c sparc SUNW,Sun_4_50

PERL 5.004_04
GCC 2.7.2
Data::Dumper 2.081
MLDBM 1.25

SCRIPT 1:
=========

#!/bin/perl -w

use strict;

my %patrick = ();
$patrick{first_name} = "Patrick";
$patrick{last_name} = "Verdon";
$patrick{post_code} = "-";
$patrick{county} = "-";
$patrick{telephone} = "-";
$patrick{email} = "-";
$patrick{anonymous} = "NO";
$patrick{notes} = "-";
$patrick{isp} = "UUNET";
$patrick{organisation} = "Some Company Inc";
$patrick{id} = "1";
$patrick{primary_contact} = "FAX";
$patrick{country} = "UK";
$patrick{address_1} = "-";
$patrick{address_2} = "-";
$patrick{city} = "-";
$patrick{fax} = "-";

my %fred = ();
$fred{first_name} = "Fred";
$fred{last_name} = "Bloggs";
$fred{post_code} = "-";
$fred{county} = "-";
$fred{telephone} = "-";
$fred{email} = "-";
$fred{anonymous} = "NO";
$fred{notes} = "-";
$fred{isp} = "UUNET";
$fred{organisation} = "Some Company Inc";
$fred{id} = "1";
$fred{primary_contact} = "FAX";
$fred{country} = "UK";
$fred{address_1} = "-";
$fred{address_2} = "-";
$fred{city} = "-";
$fred{fax} = "-";

my %joe = ();
$joe{first_name} = "Joe";
$joe{last_name} = "Smith";
$joe{post_code} = "-";
$joe{county} = "-";
$joe{telephone} = "-";
$joe{email} = "-";
$joe{anonymous} = "NO";
$joe{notes} = "-";
$joe{isp} = "UUNET";
$joe{organisation} = "Some Company Inc";
$joe{id} = "1";
$joe{primary_contact} = "FAX";
$joe{country} = "UK";
$joe{address_1} = "-";
$joe{address_2} = "-";
$joe{city} = "-";
$joe{fax} = "-";

my %people = ();
$people{1} = \%patrick;
$people{2} = \%fred;
$people{3} = \%joe;
$people{id} = 4;
my $people_ref = \%people;



for my $p ( sort { $people_ref->{$b}{last_name} cmp

{
    print("PERSON IS: $people_ref->{$p}{last_name},
$people_ref->{$p}{first_name}\n");

Quote:
}

OUTPUT:
-------

PERSON IS: Verdon, Patrick
PERSON IS: Smith, Joe
PERSON IS: Bloggs, Fred

SCRIPT 2:
=========

#!/bin/perl -w

use strict;

use Fcntl;
use NDBM_File;
use MLDBM qw(NDBM_File);

my $dbm_name = "test_dbm";
my $mode = 0775;



my %test_dbm;

tie( %test_dbm, "MLDBM", "$dbm_name", O_CREAT|O_RDWR, $mode ) ||
die("Could not access '$dbm_name'");

$test_dbm{id} = 4;

my $tmp;

$tmp = $test_dbm{1};
$tmp->{first_name} = "Patrick";
$tmp->{last_name} = "Verdon";
$tmp->{post_code} = "-";
$tmp->{county} = "-";
$tmp->{telephone} = "-";
$tmp->{email} = "-";
$tmp->{anonymous} = "NO";
$tmp->{notes} = "-";
$tmp->{isp} = "UUNET";
$tmp->{organisation} = "Some Company Inc";
$tmp->{id} = "1";
$tmp->{primary_contact} = "FAX";
$tmp->{country} = "UK";
$tmp->{address_1} = "-";
$tmp->{address_2} = "-";
$tmp->{city} = "-";
$tmp->{fax} = "-";
$test_dbm{1} = $tmp;

$tmp = $test_dbm{2};
$tmp->{first_name} = "Fred";
$tmp->{last_name} = "Bloggs";
$tmp->{post_code} = "-";
$tmp->{county} = "-";
$tmp->{telephone} = "-";
$tmp->{email} = "-";
$tmp->{anonymous} = "NO";
$tmp->{notes} = "-";
$tmp->{isp} = "UUNET";
$tmp->{organisation} = "Some Company Inc";
$tmp->{id} = "1";
$tmp->{primary_contact} = "FAX";
$tmp->{country} = "UK";
$tmp->{address_1} = "-";
$tmp->{address_2} = "-";
$tmp->{city} = "-";
$tmp->{fax} = "-";
$test_dbm{2} = $tmp;

$tmp = $test_dbm{3};
$tmp->{first_name} = "Joe";
$tmp->{last_name} = "Smith";
$tmp->{post_code} = "-";
$tmp->{county} = "-";
$tmp->{telephone} = "-";
$tmp->{email} = "-";
$tmp->{anonymous} = "NO";
$tmp->{notes} = "-";
$tmp->{isp} = "UUNET";
$tmp->{organisation} = "Some Company Inc";
$tmp->{id} = "1";
$tmp->{primary_contact} = "FAX";
$tmp->{country} = "UK";
$tmp->{address_1} = "-";
$tmp->{address_2} = "-";
$tmp->{city} = "-";
$tmp->{fax} = "-";
$test_dbm{3} = $tmp;

my $test_ref = \%test_dbm;

print("CONTENTS OF MULTI-LEVEL HASH:\n");

while ( my($key, $value) = each %test_dbm )
{
    next if ( $key eq "id" );

    print("ID: $key, NAME: $test_ref->{$key}{first_name}
$test_ref->{$key}{last_name}\n");

Quote:
}

print("\nSORTING HASH BY LAST NAME:\n");

for my $r ( sort { $test_ref->{$b}{last_name} cmp

{
    print("PERSON IS: $test_ref->{$r}{last_name},
$test_ref->{$r}{first_name}\n");

Quote:
}

untie( %test_dbm );

OUTPUT:
-------

1st run:

CONTENTS OF MULTI-LEVEL HASH:
ID: 3, NAME: Joe Smith
ID: 2, NAME: Fred Bloggs
ID: 1, NAME: Patrick Verdon

SORTING HASH BY LAST NAME:
Sort subroutine didn't return single value at sort_mldbm.pl line 96.
Segmentation Fault (core dumped)

2nd run:

CONTENTS OF MULTI-LEVEL HASH:
ID: 3, NAME: Joe Smith
ID: 2, NAME: Fred Bloggs
ID: 1, NAME: Patrick Verdon

SORTING HASH BY LAST NAME:
Bus Error (core dumped)

-----------------------

Does anyone have any idea what is going on here?

Thanks.

Patrick

P.S. Apologies for the length of this post.

--

#===============================#
\  KAN Design & Publishing Ltd  /
/  T: +44 (0)1223 511134        \
\  F: +44 (0)1223 571968        /

\  W: http://www.*-*-*.com/      /
#===============================#



Mon, 16 Oct 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. MLDBM (follow-up, sort of)

2. Sorting MLDBM records

3. taint error using MLDBM::Sync

4. Using another dbm with MLDBM.pm

5. Problem using MLDBM

6. Using MLDBM

7. Tie hash of hash using MLDBM

8. persistence problems using DB_File and MLDBM

9. untie warning when using MLDBM module

10. Problem using MLDBM

11. DB_File and seq function (using MLDBM)

12. perl sort bug on Irix?

 

 
Powered by phpBB® Forum Software