Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Working with the hex representation of the bytes adds complexity, so I started by converting the hex to bytes.

You didn't specify the type of TAG and LENGTH. I appear to have guessed wrong, or your data is broken.

use strict; use warnings; my $fh; { my $data = do { local $/; <DATA> }; $data =~ s/\s//g; $data = pack('H*', $data); open($fh, '<', \$data) or die; } my $rv = read($fh, my $hdr, 13); die "$!\n" if !defined($rv); die "Premature EOF\n" if $rv != 13; for (;;) { $rv = read($fh, my $blk_hdr, 2); die "$!\n" if !defined($rv); last if !$rv; die "Premature EOF\n" if $rv != 2; my ($tag, $len) = unpack('CC', $blk_hdr); --$len; printf("tag: 0x%02x\n", $tag); print("len: $len\n"); $rv = read($fh, my $blk_data, $len); die "$!\n" if !defined($rv); die "Premature EOF\n" if $rv != $len; print("data: ", unpack('H*', $blk_data), "\n\n"); } __DATA__ 84 47 00 0c 00 00 11 0a 03 50 35 04 00 64 0a 04 16 12 00 1e 00 1d 00 00 65 09 08 54 52 03 2f 82 05 10 00 02 6e 06 0b a8 53 11 67 00 00 00 7a 7f 00 69 4a 42 47 48 4a 41 0c 00 6a 53 54 4d 44 54 4f 1c 00 66 04 00 00 84 43 00 0c 00 00 11 09 08 43 49 29 60 64 0a 04 16 12 00 21 00 1b 00 00 65 09 08 44 80 90 0f 82 05 10 00 04 6e 06 08 ac 9b 02 67 00 00 00 7a 7f 00 69 53 54 4d 44 54 49 1f 00 6a 4b 43 47 48 51 42 3d 00
tag: 0x64 len: 9 data: 041612001e001d0000 tag: 0x65 len: 8 data: 085452032f820510 tag: 0x00 len: 1 data: 6e tag: 0x06 len: 10 data: a85311670000007a7f00 tag: 0x69 len: 73 data: 4247484a410c006a53544d44544f1c00660400008443000c0000110908434929 +60640a0416120021001b00006509084480900f82051000046e0608ac9b02670000007 +a7f006953544d tag: 0x44 len: 83 Premature EOF

In reply to Re: How to read variable data length ? by ikegami
in thread How to read variable data length ? by bh_perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-25 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found