Hi i didnt know to post this into the C threads or Perl but what i need is to convert the comand: (typedef struct {}) in C to somthing that does the same thing in Perl.
Converting C struct to Perl
Collapse
X
-
-
Converting
I have 2 pieces of code that i do not know what it means. Could someone please explain what it is saying and if anyone could could you show me a way to do it in PERL?
Code:#ifndef _ARTNET_H_ #define _ARTNET_H_
Code:#define uchar unsigned char #define ushort unsigned short int #define ulong unsigned int
-
The first two lines can be read as "if _ARTNET_H_ is not defined then define _ARTNET_H_"Originally posted by kardon33I have 2 pieces of code that i do not know what it means. Could someone please explain what it is saying and if anyone could could you show me a way to do it in PERL?
Code:#ifndef _ARTNET_H_ #define _ARTNET_H_
Code:#define uchar unsigned char #define ushort unsigned short int #define ulong unsigned int
The second line can be read as "define uchar as a synonym to unsigned char" and "define ushort to be a synonym to unsigned short int" and "define ulong to be a synonym to unsigned int".
As for a PERL interpretation you will have to ask the PERL forum. Or I can just move this post over there.Comment
-
Perl to C
Could some one help me convert that to PERL?Code:#define uchar unsigned char #define ushort unsigned short int #define ulong unsigned int typedef struct S_ArtDmx { uchar ID[8]; ushort OpCode; uchar VersionH; uchar Version; uchar Sequence; uchar Physical; ushort Universe; ushort Length; uchar Data[MaxDataLength]; } T_ArtDmx;Comment
-
You say i need to use pack if i am going to be sending the info over the net, well could you explain to me that why i could not use hash over the net to send it?Originally posted by millerIf you're just creating is a struct, then the perl equivalent would be a hash. If you're sending this information over the net and need to receive it, then you're going to need pack and unpack.
- MillerComment
-
I think i have the idea to the pack and unpack functions i am using but it still is not working write. First here is the code i need to transfer to PERL.
Im at the understanding that is saying i need to define the varible uchar and the others as an unsigned char. In PERL i think i do that by using pack with the C operator so the code i have looks like,Code:#define uchar unsigned char #define ushort unsigned short int #define ulong unsigned int
But for some reason i get the output of 2131Adam2113 instead of just char like Adam???Code:$uchar = "2131Adam2113"; pack 'C', $uchar; print $uchar;
Comment
-
A hash is an perl internal data structure. It's essentially just an associative array.
Whenever you send a C struct across the net, it often must be serialized in some way. And then the receiving end must decrypt the serialization and turn it back into a C struct.
pack and unpack are the functions that are most often used to serialize data in perl for network programming.
- MillerComment
Comment