Originally i tried to ask in the chatterbox, but i think that i may have mis-translated what i am trying to do. So without further ado:
I have an ogg/opus audio file that i am trying to read the header, which is 28 bytes or 0x1C in length. Here is the code i am using to read this header:
and here is the 28 byte header:#!/usr/bin/perl use strict; use warnings; open my $ogg_file, '<', shift or die $!; binmode($ogg_file); read_ogg_header($ogg_file); sub read_ogg_header { my ( $file ) = @_; read($file, my $buf, 28 ); my ( $ogg_magic, $ogg_version, $flags, $granule_position, $serial_ +number, $sequence_number, $checksum, $total_segments, $segment_size ) + = unpack('C4 C1 C1 C8 C4 C4 C4 C1 C1', $buf); print $ogg_magic; ### Expected it to print 'OggS' }
0x4F6767530002000000000000000083CA3DC0000000009F59730A0113
The more i think about this the more i wonder if unpack C is not what i want to do anyway. are the single bytes already in unpack C format? if so, how can i just store that value into the variable without any conversion so any further printing or processing the actual raw values eg print $ogg_magic will print "OggS"
Or maybe i am just completely confused by pack and unpack. i can use read() and i can easily print those values or translate them into expected formats, but i think unpack C is messing me up somehow? or ... OR... maybe i am just completely confused. If i need to elaborate any more please just let me know.
P.S. i guess what i am wondering in the end is, how can i make pack or unpack assign the same values as read($file, my $buf, n);? i can work with whatever data read stores (im assuming binary?) but i cannot get the same values/data to store in those variables with unpack or pack. hope i am clear, if not just give me a swift kick in the hind quarters and tell me what other info you need. and as always any help is certainly appreciated :)
In reply to pack/unpack woes by james289o9
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |