Hey,
I've been working on a module lately... It's
experimental yet, but it seems to be fully working.
I've decided about the namespace: File::Struct
because I think it'll appeal for that.
If you think that the name is not appropiate and/or
it should have another namespace, then please say so. ;-)
What the module does is sort of simulate c-style
structures for the easy i/o of binary files.
While it uses an Object Oriented interface, it also
exports constants that are data types which
you may be familiar with (it seems like magic, but
it really isn't. :) )... To explain this, here's an example code that uses the
module:
use File::Struct;
#Those act similiar to typedef in
c/c++.
use constant byte => unsigned char; use constant Ushort => unsigned short;
use constant Ulong => unsigned long; $fs = new File::Struct;
$struct = {
type => str->(4), #a string of 4 chars... version => Ushort, var1 => long, var2 => byte, var3 => doubleF, _order => [type, version, var1, var2, var3] }; $obj = $fs->CreateFromStruct($struct); #Not
really neccessery... atm, anyway.
$obj{type} = "TEST";
$obj{version} = 100; $obj{var1} = 1024; $obj{var2} = 91; $obj{var3} = 3.1415; #Write the "object" to the file
open (F, ">file.txt") or die $!; $fs->WriteObj($struct, \%obj => *F); close (F); #read from the file into the "object"
open (F, "<file.txt") or die $!; $fs->ReadObj($struct, *F => \%newObj); close (F); any comments and/or suggestions are welcome as
always.
-IR
|