Perl, treat string as binary byte array

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-06-17T21:52:06Z Indexed on 2010/06/17 22:03 UTC
Read the original article Hit count: 287

Filed under:
|
|

In Perl, is it appropriate to use a string as a byte array containing 8-bit data? All the documentation I can find on this subject focuses on 7-bit strings.

For instance, if I read some data from a binary file into $data

my $data;

open FILE, "<", $filepath;
binmode FILE;
read FILE $data 1024;

and I want to get the first byte out, is substr($data,1,1) appropriate? (again, assuming it is 8-bit data)

I come from a mostly C background, and I am used to passing a char pointer to a read() function. My problem might be that I don't understand what the underlying representation of a string is in Perl.

© Stack Overflow or respective owner

Related posts about perl

Related posts about strings