Compound data type: Difference between revisions

Content added Content deleted
(Reader included)
Line 202: Line 202:
# Please verify the code above... (from CPAN docs, not tested)
# Please verify the code above... (from CPAN docs, not tested)


# Using Class::Struct
use Class::Struct;
struct Point => [ x => '$', y => '$' ];
my $point = new Point( x => 1, y => 2 );

# Using Inline::Struct with C code embedded
# Using Inline::Struct with C code embedded
use Inline C;
use Inline C;
Line 233: Line 227:
my $point = pack("ii", 1, 2);
my $point = pack("ii", 1, 2);
my ($x, $y) = unpack("ii", $point);
my ($x, $y) = unpack("ii", $point);

# Using a hash for storage
my %point = ( x => 1, y => 2);


# Using Win32::API::Struct
# Using Win32::API::Struct
Line 268: Line 259:
#endif
#endif
typedef struct Point { int x; int y; } Point;
typedef struct Point { int x; int y; } Point;


### The code below does not create a "binary" like structure.
# Using Class::Struct
use Class::Struct;
struct Point => [ x => '$', y => '$' ];
my $point = new Point( x => 1, y => 2 );

# Using a hash for storage
my %point = ( x => 1, y => 2);


==[[PHP|PHP TODO]]==
==[[PHP|PHP TODO]]==