Platform independant way of writing hash to disk? 
Author Message
 Platform independant way of writing hash to disk?

Is there a platform independant way of writing a hash to disk?  I have been
having problems reading a hash on Linux from a file created on Solaris.  I
use DB_File and tie to read / write the hash.

S.
--
    "Revolution, n.: In politics, an abrupt change in the form of
               misgovernment." -- Devils Dictionary
Sudhakar C13n   http://www.*-*-*.com/ ; Indentured Slave



Tue, 14 Nov 2000 03:00:00 GMT  
 Platform independant way of writing hash to disk?


# Is there a platform independant way of writing a hash to disk?  I have been
# having problems reading a hash on Linux from a file created on Solaris.  I
# use DB_File and tie to read / write the hash.

Data::Dumper is slower, but works.  It stores it in plain ol' ASCII.
You'd have to reparse it on the way in, or just require it or something.
Play around, you can get it to work probably.

I don't know if the binary files created by Storable will work.  Storable
is another module to try.

--

%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])



Tue, 14 Nov 2000 03:00:00 GMT  
 Platform independant way of writing hash to disk?

Quote:

> Is there a platform independant way of writing a hash to disk?  I have been
> having problems reading a hash on Linux from a file created on Solaris.  I
> use DB_File and tie to read / write the hash.

If you don't care if it's fast, you can:

foreach $k (keys %hash) {
   write FILE "$k|$hash{$k}\n";

Quote:
}

and then read it back in in a similar fashion. Just watch out for
special characters; my example isn't exactly great code.

If you want to write a hash file which can be _efficiently_ _randomly_
accessed on multiple platforms, I don't think any of the usual
underlying db-style databases support that.

-- g



Tue, 14 Nov 2000 03:00:00 GMT  
 Platform independant way of writing hash to disk?

 [courtesy cc of this posting sent to cited author via email]


:foreach $k (keys %hash) {
:   write FILE "$k|$hash{$k}\n";
    ^^^^^
Funny man.  Whatever are you thinking?

:If you want to write a hash file which can be _efficiently_ _randomly_
:accessed on multiple platforms, I don't think any of the usual
:underlying db-style databases support that.

Think harder.  DB_File is byte-order independent.  He's just not giving
us enough information.

--tom
--
They spell it "da Vinci" and pronounce it "da Vinchy".  Foreigners
always spell better than they pronounce.
                -- Mark Twain



Tue, 14 Nov 2000 03:00:00 GMT  
 Platform independant way of writing hash to disk?

Quote:

> :foreach $k (keys %hash) {
> :   write FILE "$k|$hash{$k}\n";
>     ^^^^^
> Funny man.  Whatever are you thinking?

fortran

Quote:
> :If you want to write a hash file which can be _efficiently_ _randomly_
> :accessed on multiple platforms, I don't think any of the usual
> :underlying db-style databases support that.

> Think harder.  DB_File is byte-order independent.  He's just not giving
> us enough information.

Neither the manpage nor Programming Perl v2 chapter 7 says that, but I
read the source, and it's true. Golly gee. I know gdbm gets this wrong,
which is one of the reasons it got abandoned...

-- g



Tue, 14 Nov 2000 03:00:00 GMT  
 Platform independant way of writing hash to disk?

Quote:

> Neither the manpage nor Programming Perl v2 chapter 7 says that, but I
> read the source, and it's true. Golly gee. I know gdbm gets this wrong,
> which is one of the reasons it got abandoned...

Now I have to eat those words, page 380 has a nice chart comparing dbm
implementations, and notes that bsd-db is the only one which is
byte-order independent. So it's mostly cosmetic that it isn't
mentioned anywhere in the DB_File section.

But I'll stand by my claim that I was thinking FORTRAN.

-- g



Tue, 14 Nov 2000 03:00:00 GMT  
 Platform independant way of writing hash to disk?

 [courtesy cc of this posting sent to cited author via email]


:Neither the manpage nor Programming Perl v2 chapter 7 says that,

Wrong.

   Here's a partial table of features the different packages offer:

                            odbm    ndbm    sdbm    gdbm    bsd-db
                            ----    ----    ----    ----    ------
    Linkage comes w/ perl   yes     yes     yes     yes     yes
    Src comes w/ perl       no      no      yes     no      no
    Comes w/ many unix os   yes     yes[0]  no      no      no
    Builds ok on !unix      ?       ?       yes     yes     ?
    Code Size               ?       ?       small   big     big
    Database Size           ?       ?       small   big?    ok[1]
    Speed                   ?       ?       slow    ok      fast
    FTPable                 no      no      yes     yes     yes
    Easy to build          N/A     N/A      yes     yes     ok[2]
    Size limits             1k      4k      1k[3]   none    none
 *  Byte-order independent  no      no      no      no      yes
    Licensing restrictions  ?       ?       no      yes     no

--tom
--
Churchill's Commentary on Man: Man will occasionally stumble over the
truth, but most of the time he will pick himself up and continue on.



Tue, 14 Nov 2000 03:00:00 GMT  
 Platform independant way of writing hash to disk?


| ,
|
| # Is there a platform independant way of writing a hash to disk?  I have been
| # having problems reading a hash on Linux from a file created on Solaris.  I
| # use DB_File and tie to read / write the hash.
|
| Data::Dumper is slower, but works.  It stores it in plain ol' ASCII.
| You'd have to reparse it on the way in, or just require it or something.
| Play around, you can get it to work probably.
|
| I don't know if the binary files created by Storable will work.  Storable
| is another module to try.

I'm sure someone better knowledgeable with different modules will find
the best solution, but I'm on impression that combo:

    FreezeThaw + Storable

gives you platform independency. I'm hoping that more of the greatest
(like these) would come standard with Perl.

jari



Sun, 19 Nov 2000 03:00:00 GMT  
 Platform independant way of writing hash to disk?



# | Data::Dumper is slower, but works.  It stores it in plain ol' ASCII.
# | You'd have to reparse it on the way in, or just require it or something.
# | Play around, you can get it to work probably.
# |
# | I don't know if the binary files created by Storable will work.  Storable
# | is another module to try.
#
# I'm sure someone better knowledgeable with different modules will find
# the best solution, but I'm on impression that combo:
#
#     FreezeThaw + Storable
#
# gives you platform independency. I'm hoping that more of the greatest
# (like these) would come standard with Perl.

First, all three (Data::Dumper, Storable, FreezeThaw) should work on any
platform, though Storable must be compiled.  But the point wasn't whether
the CODE would be cross-platform, but whether the files written out by the
modules would be cross-platform.  i.e., can I write a Storable file on
Linux and read it on a Mac?

I don't know.

--

%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])



Sun, 19 Nov 2000 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Writing to a file when disk is full?

2. ANNOUNCE: LibA2 0.003 (read/write Apple II ProDOS disk images)

3. Corrupted disk writes with SDBM

4. Perl Programme written on different platforms

5. Problem Writing extension in C on windows NT platform

6. deleting from dbm-tied hash: disk sync.

7. Make a perl script independant of shell

8. HOW-TO keep this [#!/usr/bin/perl] independant of server

9. Perl 5 regexps as independant package?

10. Hashes of Hashes of Hashes of Hashes....

11. URGENT: Hash in Hash, Array in Array, Array in Hash, Hash in Array

12. file parse into hash and writing output with certain format to new file

 

 
Powered by phpBB® Forum Software