Perl substr replacement?

Steven ~

New member
Hi,
I'm working with packets in Perl, and cannot remember how to fill in blank spaces using substr.

For example. I have \x00\x00\x00\x00, but the combined packet has to be at least \x00\x00\x00\x00\x00\x00. How would I be able to add the last 2 \x00s on using substr?

Currently, I have this (I know, it fails. I'm trying to reproduce something I made a year ago)

my $packet = "\xf8\x2a";
my $fullpacket;
$fullpacket = substr($packet, length($packet), 23-length($packet), "\x00"x(23-length($packet)));
$fullpacket =~ s/(.)/sprintf("%x",ord($1))/eg;
print($fullpacket);
 
Back
Top