in reply to Splitting Binary Data
Shouldn't
foreach(split(//,$response)) {
be
foreach(split(//,$response->content)) {
if (!$response->is_success) { should be before the loop, not in it.
What follows is the above fixes, in addition to unpacking two bytes at a time instead of one:
if (!$response->is_success) { die $response->status_line; } my $content = $response->content(); $content =~ s/^(..)//; # One of these, depending on byte ordering of the source. my $index = unpack('n', $1); #my $index = unpack('v', $1); printf("index: %04x\n", $index); while ($content =~ /(..)/g)) { # One of these, depending on byte ordering of the source. my $int16 = unpack('n', $1); #my $int16 = unpack('v', $1); $int16 -= 65536 if ($val > 32767); print($int, ' '); } print "\n";
Update: I wasn't converting them to signed numbers.
|
|---|