dbmopen differences in perl4 and perl5 
Author Message
 dbmopen differences in perl4 and perl5

Hi,

I know there have been similar question regarding perl4 and perl5 in regard to
dbmopen, but I would really appreciate help with this.

The following code works using perl4, printing out all the keys with values,
however using perl5.001, the locationx array has keys but no values associated
with each key.    If I print out the keys and values of location both are
printed out.

dbmopen(%locationx,"$lib/loc",0644);
%locationx = %location;
while (($key,$value) = each %locationx) {
                print "$key=$value\n"; }
dbmclose(%locationx);

How therefore do I make %locationx equal to %location?

Janice



Mon, 14 Sep 1998 03:00:00 GMT  
 dbmopen differences in perl4 and perl5


Quote:
>Hi,

>I know there have been similar question regarding perl4 and perl5 in regard to
>dbmopen, but I would really appreciate help with this.

>The following code works using perl4, printing out all the keys with values,
>however using perl5.001, the locationx array has keys but no values associated
>with each key.    If I print out the keys and values of location both are
>printed out.

>dbmopen(%locationx,"$lib/loc",0644);
>%locationx = %location;
>while (($key,$value) = each %locationx) {
>            print "$key=$value\n"; }
>dbmclose(%locationx);

>How therefore do I make %locationx equal to %location?

>Janice


This works ok for me with both perl4 and perl5.  e.g. -

    dbmopen(%locationx,"loc",0644);
    $location{'Foo'} = 'baz';
    $location{'Baz'} = 'foo';
    %locationx = %location;
    while (($key,$value) = each %locationx) {
                    print "$key=$value,"; }
    dbmclose(%locationx);

# perl4 prints: Foo=baz, Baz=foo,
# perl5 prints: Foo=baz, Baz=foo,

It appears that some people have been bitten somehow by
5.002 and dbm files, if the compilation of perl5 did not link
the perl binary with -ldbm or -lndbm.  (as was the default with perl4
on OS's that had it.) I really dont have a clear picture of what happened
yet, but there is a workaround.  You can use  tie() to force the use of
the dbm library  and be assured of opening pre-existing dbm files created
by perl4 or other means.  

You can find this trap, and others, documented with examples in 425traps.  

$CPAN/authors/id/BMIDD/425traps.gz

Here's a script which will do what you want with tie()

    use Fcntl;
    use NDBM_File;

    use NDBM_File;
    tie(%locationx, NDBM_File, 'loc', O_RDWR|O_CREAT, 0644);
    %locationx = %location;  
    while (($key,$val) = each %locationx) {
        print $key, ' = ', $val, "\n";
    }  
    untie(%locationx);

Bill



Mon, 14 Sep 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. perl5/perl4 bit-wise OR difference

2. Please explain this perl4/perl5 difference...

3. What's the differences between perl4 and perl5

4. perl4/perl5 differences

5. Perl4 and Perl5 DBM differences

6. What are the differences between Perl4.xxx and Perl5

7. Multiple dbmopen()'s at once (perl4)

8. dbmopen/dbmclose:perl4/5 conversion

9. Can I use dbmopen command with perl4??

10. 'while'-difference in perl5.001m and perl5.003

11. Subtle perl4/5 difference: goto loop label

12. subtle perl4/5 difference: "${q[1]}"

 

 
Powered by phpBB® Forum Software