in reply to Re: How can I modify received socket messages in Perl?
in thread How can I modify received socket messages in Perl?

I am sorry that I didn't tell things clearly. I just want to insert 3 bytes into received msg between the header and body, but not in the front or end.

Can substr() work?
  • Comment on Re^2: How can I modify received socket messages in Perl?

Replies are listed 'Best First'.
Re^3: How can I modify received socket messages in Perl?
by ikegami (Patriarch) on Mar 10, 2009 at 02:52 UTC
    You don't have a header and body, just a bunch of bytes. First things first, you need to identify the header and the body.
      Yes,you're right. I know I have to identify the header and body, that's why I convert messages in $buffer(binary) into @msg.
      The question is after I insert 3 bytes into @msg, I don't know how to convert modified message in @msg into the type that can be sent out by syswrite().

        I doubt it's necessary or even helpful to create @msg.

        And populating it with the hex nibble pairs is particularly backwards. Populating it with the values of each bytes would make more sense if there's any reason to create @msg in the first place.

        my @msg = unpack('C*', $buffer); ...do something to @msg... $buffer = pack('C*', @msg);